IdTCPServer接收16进制数组
小弟第一次接触通信这块,不明白怎么使用IdTCPServer接收客户端发送的16进制数组,请高手指教,不胜感激。
[解决办法]
//C++Builder 6.0
void __fastcall TForm1::Button1Click(TObject *Sender)
{
byte a[2] ={0xAA,0xBB} ;
IdTCPClient1->WriteBuffer(a,2,2);
}
void __fastcall TForm1::IdTCPServer1Execute(TIdPeerThread *AThread)
{
byte a[2] ;
AThread->Connection->ReadBuffer(a,2) ;
AnsiString s;
for(int i=0;i<2;i++)
s +=IntToHex(a[i],2);
Memo2->Lines->Add(s);
}
//---------------------------------------
//C++Builder 2009
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(!IdTCPClient1->Connected())
{
IdTCPClient1->Connect();
}
IdTCPClient1->IOHandler->WriteLn("汉字123abcd",enUTF8);
IdTCPClient1->Disconnect();
}
//TIdTCPServer端的onExcute事件:
void __fastcall TForm2::IdTCPServer1Execute(TIdContext *AContext)
{
UnicodeString CmdString =AContext->Connection->IOHandler->ReadLn(enUTF8);
}