Hi Marc,
Your code works perfectly :)
It created the "UniqueID" for the client and I believe this just was what I needed. Now I will be able to select the client of my choice with this ID.
I will do the rest and start testing.

Thanks a lot for the great help :)

Best regards

-----Original Message----- From: Marc Charbonneau
Sent: Tuesday, January 18, 2011 3:58 PM
To: ICS support mailing
Subject: Re: [twsocket] SslWSocketServer & SslWSocket

Thanks Marc,
Have been playing 2 days with this and still can't find out the way how to
do.

Ok, here's a simple solution with TcpSrv demo :

In TTcpSrvForm declaration, in the private part, add this

   FClientNo : integer;

Now, go in procedure TTcpSrvForm.WSocketServer1ClientConnect and
change the code to look like this :
procedure TTcpSrvForm.WSocketServer1ClientConnect(
   Sender : TObject;
   Client : TWSocketClient;
   Error  : Word);
begin
   with Client as TTcpSrvClient do begin
       Inc(FClientNo); // Increment unique client no
       Tag := FClientNo; // tag connecting client with it's id
       Display('Client connected. UniqueID : ' + IntToStr(Tag) +
               ' Remote: ' + PeerAddr + '/' + PeerPort +
               ' Local: '  + GetXAddr + '/' + GetXPort);
       Display('There is now ' +
               IntToStr(TWSocketServer(Sender).ClientCount) +
               ' clients connected.');
       LineMode            := TRUE;
       LineEdit            := TRUE;
       LineLimit           := 80; { Do not accept long lines }
       OnDataAvailable     := ClientDataAvailable;
       OnLineLimitExceeded := ClientLineLimitExceeded;
       OnBgException       := ClientBgException;
       ConnectTime         := Now;
   end;
end;

Now, change your SendCommand procedure to something like this :

procedure TTcpSrvForm.SendCommand(ClientNo: integer; CommandText: string);
var
 i: integer;
begin
for i := 0 to WSocketServer1.ClientCount -1 do
begin
 // iterate all client trying to find the right one
  if WSocketServer1.Client[i].Tag = ClientNo then
  begin
    WSocketServer1.Client[i].SendStr(CommandText);
    Display('Command sent: ' + CommandText);
   break;
  end;
end;
end;

This should do what you want.

hope this help

Marc
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to