How to handle received data in the TCPClient ? (Delphi - Indy)

后端 未结 5 606
梦如初夏
梦如初夏 2021-02-01 22:59

When i send a message from TCPClient to a TCPServer it will be handled using OnExecute event in the server . Now i want to handle the rece

5条回答
  •  一整个雨季
    2021-02-01 23:31

    If you need the Indy client to handle incoming "messages" (definition of "message" depends on the protocol used), I recommend to take a look at the implementation of TIdTelnet in the protocols\IdTelnet unit.

    This component uses a receiving thread, based on a TIdThread, which asynchronously receives messages from the Telnet server, and passes them to a message handler routine. If you have a similar protocol, this could be a good starting point.

    Update: to be more specific, the procedure TIdTelnetReadThread.Run; in IdTelnet.pas is where the asynchronous client 'magic' happens, as you can see it uses Synchronize to run the data processing in the main thread - but of course your app could also do the data handling in the receiving thread, or pass it to a worker thread to keep the main thread untouched. The procedure does not use a loop, because looping / pausing / restarting is implemented in IdThread.

提交回复
热议问题