Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: what is the best way to send the client list from idtcpserver ?



Permlink Replies: 2 - Last Post: Mar 6, 2018 3:02 PM Last Post By: madammar ellias
madammar ellias

Posts: 111
Registered: 8/17/17
what is the best way to send the client list from idtcpserver ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2018 1:58 PM
i am currently do this to send all connected clients From server To the client by doing the following

loop through context list save each client to string list send them in memory stream


procedure TConnection.Senduserlist;
var
  I: integer;
  ClientlistStringL: TStringList;
  MS: TMemoryStream;
  Connection: TConnection;
  List: TList; // or TIdContextList if using a modern Indy version
begin
 
 
 
List := Server.Contexts.LockList;
    
 try
 
ClientlistStringL := TStringList.Create;
  try
 
  for I := 0 to List.Count - 1 do
  begin
  Connection := TConnection(List.Items[I]);
  
ClientlistStringL.Add(Connection.Name + connection.imgblobstring + connection.ipaddr);
  end;
 
 
  MS := TMemoryStream.Create;
 
  try
 
  if (ClientlistStringL.Count > 0) then
  begin
  ClientlistStringL.SaveToStream(MS, TEncoding.UTF8);
  MS.Position := 0;
  end;
 
  self.SendCommandAndStream('ClIENTLST', MS);
 
  finally
    FreeAndNil(MS);
  end;
 
  finally
    FreeAndNil(ClientlistStringL);
  end;
 
 
 
  finally
  Server.Contexts.UnlockList;
  end;
 
end;
 


but there is view problems when the clients
increased to 100 the memory size became too big to handle receive on some connections that causes disconnects if the memory size is too big in suggestions ?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: what is the best way to send the client list from idtcpserver ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2018 2:32 PM   in response to: madammar ellias in response to: madammar ellias
madammar ellias wrote:
i am currently do this to send all connected clients From server To the client by doing the following

loop through context list save each client to string list send them in memory stream

You are not placing any kind of delimiter between a client's Name, ImgBlobString, or IPAddr, so how do you expect the recipient of the list to know what is what?

Also, you are keeping the server's Contexts list locked while transmitting the TStringList. I would suggest rearranging the code so the Contexts list is locked only while populating the TStringList and is unlocked before transmitting.

self.SendCommandAndStream('ClIENTLST', MS);

Why is the 'L' in 'CLIENT' lowercase instead of uppercase?

but there is view problems when the clients

I would imagine so, since you haven't formatting the data in a nice format that is easy to parse.

increased to 100 the memory size became too big to handle receive on some connections that causes disconnects if the memory size is too big

That has noting to do with the code you have showed. You are probably doing something wrong on the receiver side, but you didn't show that code.

--
Remy Lebeau (TeamB)
madammar ellias

Posts: 111
Registered: 8/17/17
Re: what is the best way to send the client list from idtcpserver ?
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2018 3:02 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

You are not placing any kind of delimiter between a client's Name, ImgBlobString, or IPAddr, so how do you expect the recipient of the list to know what is what?

Also, you are keeping the server's Contexts list locked while transmitting the TStringList. I would suggest rearranging the code so the Contexts list is locked only while populating the TStringList and is unlocked before transmitting.

self.SendCommandAndStream('ClIENTLST', MS);

Why is the 'L' in 'CLIENT' lowercase instead of uppercase?

but there is view problems when the clients

I would imagine so, since you haven't formatting the data in a nice format that is easy to parse.

increased to 100 the memory size became too big to handle receive on some connections that causes disconnects if the memory size is too big

That has noting to do with the code you have showed. You are probably doing something wrong on the receiver side, but you didn't show that code.

--
Remy Lebeau (TeamB)

each connection string that was sent have prefix separator as ~ i could use extra cont variable to add between each list item in the string list

receiving side

  
 
FMSFROMCALL := nil;
try
 
FMSFROMCALL := TMemoryStream.Create;
FTCP.IOHandler.LargeStream := True;
FTCP.IOHandler.ReadStream(FMSFROMCALL, -1, false);
FMSFROMCALL.Position := 0;
FSTREAM := True;
if Assigned(FOnCallbackProc) then
begin
Synchronize(DoCallbackProc);
end;
 
finally
FMSFROMCALL.Free;
end;


on parsing process

  
var
SL: TStringList;
starting : string;
I: Integer;
namec, imgc, ipc : string;
begin
 
SL := TStringList.Create;
try
if Assigned(MSCLIENT) then
begin
SL.LoadFromStream(MSCLIENT);
 
 
for I := 0 to SL.Count - 1 do
begin
starting := SL.Strings[I];
 
parsedata(starting, namec, imgc, ipc);
 
addtolistview(namec, imgc,ipc)
 
 
 
end;
 
end;
 
 
 
finally
FreeAndNil(SL);
end;
 
 
end;
 
//parser
 
procedure parsedata(starting: string; var namec, imgc, ipc: string);
var
  P, I: Integer;
begin
I := 0;
repeat
P := Pos('~', starting);
if P <> 0 then
begin
Inc(I);
case I of
1: namec:= Copy(starting, 1, P - 1);
2: imgc:= Copy(starting, 1, P - 1);
3: ipc:= Copy(starting, 1, P - 1);
end;
Delete(starting, 1, P + Length(Sep) - 1);
end;
until (I = 3) or (P = 0) or (starting = '') end;
 
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02