2012-04-12 15 views
6

Tengo un TIdHttpServer, debo mantener la conexión abierta para enviar algunos comandos a los clientes. Quiero iterar cuando presiono un botón y envío un comando a todos los clientes conectados.Mandato de envío a todos los clientes conectados

¿Cómo puedo hacer esto?

+2

Versión de indy? – RRUZ

+0

Uso delphi xe 2 con indy 10 – opc0de

Respuesta

10

Puede usar la propiedad Contexts para obtener los clientes y luego usar el IOHandler de cada cliente puede enviar un mensaje.

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; 
Cuestiones relacionadas