开发者

How to use IdThreadComponent in c++ builder

开发者 https://www.devze.com 2023-02-24 08:07 出处:网络
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 TIdThrea

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消