Send command to all connected clients

I have a TIdHttpServer, I have to open a connection to send some commands back to clients. I want iteration when I click a button and send a command to all connected clients.

How can i do this?

+6
source share
1 answer

You can use the Contexts property to receive clients, and then using the IOHandler each client you can send a message.

 Var Clients : TList; i : integer; begin if not Assigned(IdTCPServer1.Contexts) then exit; Clients:=IdTCPServer1.Contexts.LockList; try for i := 0 to Clients.Count-1 do try TIdContext(Clients[i]).Connection.IOHandler.Write(LBuffer);//LBuffer is a TBytes with the data to send except ... end; finally IdTCPServer1.Contexts.UnlockList; end; end; 
+10
source

Source: https://habr.com/ru/post/912999/


All Articles