Currently I'm success fully make server and client using TIdTCPServer and TIdTCPClient Indy components, but I got a trouble when two client connect to the server at the same time. I have two networks 192.168.10.23 and localhost, when client connect using localhost it's fine and the second client try connect to 192.168.10.23 there still waiting for first client disconnect.
can anyone please give me advice how to handle multiple client using Indy10.
Added:
This my code:
void __fastcall TfrmServer::TCPServerConnect(TIdContext *AContext)
{
TList *list = TCPServer->Contexts->LockList();
try
{
for (int j=0; j < list->Count; j++)
{
TIdContext *myContext = static_cast<TIdContext*>(list->Items[j]);
CLIENT_AUTH(myContext);
INFO_CLIENT *br = ((INFO_CLIENT*)brb);
br->ClientIP = myContext->Binding()->IP;
br->ClientPort = myContext->Binding()->Port;
br->peerIp = myContext->Binding()->PeerIP;
br->peerPort = myContext->Binding()->PeerPort;
if (myContext->Connection->Connected())
{
for (int i=0; i < list->Count; i++)
{
ListIt = ListClient->Items->Add();
ListIt->Caption = String(i+1); // number
ListIt->SubItems->Add(br->UserName); // Name
ListIt->SubItems->Add(br->ClientIP); // Ip
ListIt->SubItems->Add(br->peerIp); // Peer Ip
ListIt->SubItems->Add(br->ClientPort); // port
ListIt->SubItems->Add(br->peerPort); // port
ListIt->SubItems->Add("Connected"); // Status
}
}
}
}
__finally
{
TCPServer->Contexts->UnlockList();
}
}
Did this code have supports for multiple client ?
TIdTCPServer::Contextslist is locked (which you should not be doing at all), no additional clients can connect to the server. And you are manipulating the UI from outside the context of the main thread, which can cause crashes and deadlocks. You need to re-write this code. - Remy Lebeau