How to use IdThreadComponent with TIdyTCPServer in c++ bu开发者_StackOverflow中文版ilder????
Please help!
TIdTCPServer
is multi-threaded internally for you. You don't need to use TIdThread
or TIdThreadComponent
directly.
You can reach context on handling methods directly
void __fastcall TCPServer::OnDisconnect(TIdContext *AContext){
AContext->Binding()->PeerIP //Returns IP Of the just connected client
AContext->Binding()->PeerPort;
}
Messages can be read onExecute event
AContext->Connection->Socket->ReadBytes(buf, 4, false);
Also in anywhere of your program, you can reach the context like that:
TList *list = IdTCPServer1->Contexts->LockList();
for(int i=0; i<IdTCPServer1->Contexts->LockList()->Count; i++){
TIdContext *AContext = (TIdContext*)(list->Items[i]);
if(AContext ->Binding()->PeerIP == clientIP){ // say you want to reach the context of a specified IP
//Do something
}
}
IdTCPServer1->Contexts->UnlockList();
精彩评论