|  | 
| Is it possible to combine TIdTCPServer components with TClientSocket ? - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Open Source (https://www.atozed.com/forums/forum-19.html) +--- Forum: Indy (https://www.atozed.com/forums/forum-9.html) +--- Thread: Is it possible to combine TIdTCPServer components with TClientSocket ? (/thread-3080.html) | 
| Is it possible to combine TIdTCPServer components with TClientSocket ? - Max2009 - 03-20-2023 Hello. I am using Embarcadero C++ and I have Indy 10.6.2.0 installed. I have 4 components on my form: TIdTCPClient *Client; TIdTCPServer *Server; TClientSocket *ClientSocket; TServerSocket *ServerSocket; Client is configured to connect to Server; ClientSocket is configured to connect to ServerSocket; If I assign ClientConnect() to Button1::OnClick event, it connects successfully. If I assign ClientSocket->Active=true to Button2::OnClick event, it also connects successfully. However, if I try to connect by setting ClientSocket->Active=true in Server::OnConnect event: { ClientSocket->Active=true; } It doesn't work. The same is true if I try to connect in OnContextCreate or OnExecute events. Why is this happening? RE: Is it possible to combine TIdTCPServer components with TClientSocket ? - rlebeau - 03-20-2023 (copied from my answer to your same question on StackOverflow): Quote:By default, TClientSocket operates in non-blocking mode (TClientSocket::ClientType = ctNonBlocking). In that mode, the client uses an HWND window internally to handle socket events. It also means that the client connects to its server asynchronously, delivering a completion event to its HWND once the connection is successful or fails. RE: Is it possible to combine TIdTCPServer components with TClientSocket ? - Max2009 - 03-21-2023 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. RE: Is it possible to combine TIdTCPServer components with TClientSocket ? - rlebeau - 03-21-2023 (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: 
 RE: Is it possible to combine TIdTCPServer components with TClientSocket ? - Max2009 - 04-09-2023 Another problem has arisen. When a client is connected to TIdTCPServer *Server, OnConnect is triggered, but when the client is disconnected, OnDisconnect does not trigger, and it only triggers when the server is disconnected by setting Server->Active=false. Why is this happening? RE: Is it possible to combine TIdTCPServer components with TClientSocket ? - rlebeau - 04-10-2023 The TIdTCPServer.OnDisconnect event is fired when the server thread that owns the socket is being shut down. There are 2 reasons I can think of for why that event might not happen when you are expecting it: 
 |