indy Tidtcpserver best  way to brodcast message to multiable clients

drama22
drama22 used Ask the Experts™
on
i have this code that send data to each client connected where client value equals to something

procedure TConnection.BroadCastTextMessage(const TextMessage: String;
const FromUniqueID: Dword; const FromName: string);
var
  List: TList;
  I, J: integer;
  Connection: TConnection;
  Channel: string;
begin
  List := Server.Contexts.LockList;
  try
    for I := 0 to List.Count - 1 do
    begin
      Connection := TConnection(List.Items[I]);
      if Connection.UniqueID = FromUniqueID then
      begin
        Channel := Connection.Channel;
        for J := 0 to List.Count - 1 do
        begin
          Connection := TConnection(List.Items[J]);
          if (Connection <> Self) and (Connection.Channel= Channel) then
          begin
            try
              Connection.SendCommandWithParams('TEXTMESSAGE',
                FromName + Sep + TextMessage + Sep);
            except
            end;
          end;
        end;
        Exit;
      end;
    end;
  finally
    Server.Contexts.UnlockList;
  end;
end;

Open in new window


this code brodcats  a text to each client connected where this client channle variable equals to sender is this the best way to do  ? also i want to add more stuff like if (Connection <> Self) and (Connection.Channel= Channel)  and connection.otherdata = same data to each client connected should i use self.otherdata then ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software architect
Top Expert 2012
Commented:
Looks good to me ... I would check if client is still connected before....
...
if (Connection <> Self) and (Connection.Channel= Channel) and Connection.Connected then
...

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial