Hello All, Ok I got a problem with my code below it generates a userlist for my chat system now the problem am having when it generates list and some one is logging in or out while generating the list it will do fake names that don't exist

function GetLobbyUsers(const aLobbyID: string): string;
     i: Integer;
     HostID: string;
     Result := '';
     for i := 0 to (SocketServer.ClientCount -1) do
       if (CompareText(SocketServer.Client[i].Lobby, aLobbyID) = 0) then
         HostID := '';
HostID := IntToStr(Integer(CompareText(SocketServer.Client[i].LobbyOwner, SocketServer.Client[i].Name) = 0));
         SocketServer.Client[i].HasHighLatancy := False;
         SocketServer.Client[i].HasLowLatancy := False;
         SocketServer.Client[i].IsCheckingLatancy := True;
         Result := Result + 'š11œ' + aLobbyID + 'œ'
           + SocketServer.Client[i].Name + 'œ'
           + SocketServer.Client[i].Rank + 'œ'
           + SocketServer.Client[i].IconNumber + 'œ'
           + SocketServer.Client[i].BIconNumber + 'œ'
           + MBoolToStr(SocketServer.Client[i].IsAFK) + 'œ'
           + HostID + 'œ'
           + SocketServer.Client[i].HasTrophy + 'œ'
           + MBoolToStr(SocketServer.Client[i].IsDownloading) + 'œ'
           + MBoolToStr(SocketServer.Client[i].HasHighLatancy) + 'œ'
           + MBoolToStr(SocketServer.Client[i].HasLowLatancy) + 'œ'
           + MBoolToStr(SocketServer.Client[i].IsCheckingLatancy) + 'œ'
           + MBoolToStr(SocketServer.Client[i].IsBlocked) + 'œ';

I looked this up and it maybe this issue here, Being a chat system and assuming SocketServer.Client is the list of connected users, is it possible that users are connecting and disconnecting while you are still iterating the list of users? If so, then SocketServer.ClientCount could be modified while you are still iterating which would be very bad. This might explain why you get fake users (i.e. disconnected while iterating) or missing users (connected while still iterating). If this is the case, then you might need to lock SocketServer.Client while you are iterating it i.e. prevent adding or removing items from the list. Or maybe create a copy of SocketServer.Client and iterate the copy. Regardless, performance is critical so you need to iterate the list of users very quickly.

anyone got any advice or can help me recode to better solution thanks alot
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