Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to combine TIdTCPServer components with TClientSocket ?
#4
(03-21-2023, 02:59 AM)Max2009 Wrote: Yes, the connection worked. The TClientSocket component has a good OnRead property, which means that I can connect to the server and have a constant connection. Data comes from the server and I can read it immediately without reconnecting. Is there a similar possibility in TIdTCPClient? The component has an OnConnect property, but it only triggers once. It is unclear how to receive data without reconnecting.

The TClientSocket.OnRead event operates asynchronously only. You must use the TClientSocket in non-blocking mode, which means it uses an internal window, and so the owning thread must have a message pump to dispatch window messages. The TClientSocket.OnRead event is fired whenever the client's internal window receives an FD_READ notification from the socket.

TIdTCPClient, on the other hand, operates synchronously only, there are no events (the OnConnect event is merely a callback that is called by TIdTCPClient.Connect() before it returns to its caller). If you need to receive data asynchronously from a server using TIdTCPClient, you must either:
  • have a worker thread read from the TIdTCPClient.IOHandler in a blocking manner, and then delegate received data where needed.
  • or else, have the main thread use a UI timer or sleep loop to periodically poll the TIdTCPClient.IOHandler for new data using a short timeout, and then use any received data as needed.

Reply


Messages In This Thread
RE: Is it possible to combine TIdTCPServer components with TClientSocket ? - by rlebeau - 03-21-2023, 05:11 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)