How to send a message to all clients connected to TidTcpServer. lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- SniperX · 2016-08-04 17:58 I read some post from Remy stating that all the messages to the connected clients should be sent from within the OnExecute handler rather than the GUI itself. But then i saw this thread on stackoverflow http://stackoverflow.com/questions/14173140/tidserver- about-synchronization-again where a user created a derived class from TidSeverContext and queued up all the string based messages in it but what about a scenario where i need to use a combination of more than 2 or more methods from IOHandler class to form a proper message which could include writing Integer values to socket or TStream or lets say even a string (just a example). ---------------------------------------------------------------------- Remy Lebeau · 2016-08-10 01:49 Quote from: SniperX on August 04, 2016, 07:58:22 pmI read some post from Remy stating that all the messages to the connected clients should be sent from within the OnExecute handler rather than the GUI itself. Yes.  That is the safest option.  It prevents 1) deadlocks, 2) failed clients from causing problems for other clients, and 3) outgoing TCP messages from overlapping each other on the wire. Quote from: SniperX on August 04, 2016, 07:58:22 pmBut then i saw this thread on stackoverflow http://stackoverflow.com/questions/14173140/tidserver-about- synchronization-again where a user created a derived class from TidSeverContext and queued up all the string based messages in it That is just a convenient way to allow outside threads to add messages to a client's queue whenever needed, and then that client's OnExecute event checks the queue for new messages to send to the client.  I have demonstrated that kind of coding technique with TIdTCPServer many times. Quote from: SniperX on August 04, 2016, 07:58:22 pmbut what about a scenario where i need to use a combination of more than 2 or more methods from IOHandler class to form a proper message which could include writing Integer values to socket or TStream or lets say even a string (just a example). Once the OnExecute handler detects a queued message is available to be sent, the code can send the message however it needs to, however many IOHandler calls it takes.  The point is, by putting all of the writing logic in OnExecute, outgoing messages are serialized to avoid overlapping, and the client thread decides when it is safe to send each message so it does not get interrupted by other things (except maybe a socket disconnect).  The actual writing logic is up to you, based on your protocol needs.  Use whatever IOHandler calls you want per message.  Usually the examples are just strings, but there is nothing stopping you from sending other kinds of data.