源:IdTCP的C++Builder2010示例

IdTCP的C++Builder2010示例

这个是服务端的:

void __fastcall TTCPDataServer::TCPServerExecute(TIdContext *AContext)
{
AnsiString Str;
Str=AContext->Connection->IOHandler->ReadLn();
if (Str=="")
Str="Error,String is Emtry";
AContext->Connection->IOHandler->WriteLn(Str);
AContext->Connection->Disconnect(true);
}

这个是客户端的:

try
{
IdTCPClient->Connect();
}
catch(Exception &e)
{
ShowMessage(e.Message);
}
IdTCPClient->IOHandler->WriteLn("");
ShowMessage(IdTCPClient->IOHandler->ReadLn());
IdTCPClient->Disconnect();
05-11 14:49