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 ?
TIdTCPServersupports multiple simultaneous connections on multiple networks and that works just fine. If your clients are serializing with each other, then the problem has to be in your own code or networking setup. Indy does not prevent multiple clients from connecting to the same server at the same time.Update: try this: