I have a very simple app, with 10 clients & 2 servers. Each client sends a heartbeat to both servers every 10 seconds. It may also, every few minutes, triggered by an external event, send another string to a TIdCmdTCPServer at the server and wait for a response.
I am a networking novice. To keep matters simple, I would like to make a blocking call (since the system is so simple) – client sends a message to server and blocks, waiting for a reply (or a timeout).
Can I do that? Or do I need to buffer my messages, and wait at the client for a reply (or timeout) before sending the next?
Windows 7 pro, Indy 10, Delphi XE2
Indy uses blocking I/O exclusively, so what you are asking for is doable, in fact it is exactly how Indy works under most situations. Just perform a write operation and wait for it to return, then you can perform a reading operation immediately. In fact, since you are already using
TIdCmdTCPServeron the server side, you can useTIdTCPClient.SendCmd()on the client side to send a command and wait for its response in a single operation.Just note that because Indy is blocking, you should use
TIdTCPClientin a worker thread if you do not want to block your main thread, which would make a UI unresponsive whileTIdTCPClientis busy.