想要一个在indy10下,用内存流发送结构的例子,最好是同步通信的
使用BCB2010,indy10,需要内存流发送结构的例子,最好是同步通信的
[解决办法]
void __fastcall TForm2::IdTCPServer1Execute(TIdContext *AContext){ comuniContent aComuniContent ; userInfo aUser; pCInfo CInfo ; TMemoryStream * Strm = new TMemoryStream (); try { try { //这里直接转换成结构体了 AContext->Connection->IOHandler->ReadStream(Strm,sizeof(comuniContent)); Strm->Position = 0 ; // //注意 这个地方还原了结构体aComuniContent // Strm->ReadBuffer(&aComuniContent,sizeof(comuniContent)); //得到了结构体了 aUser = aComuniContent.user; CInfo = aComuniContent.host ; //其他的结构体类似 你自己去完成吧 Memo1->Lines->Add("唯一标识符:"+AnsiString(aComuniContent.SN)); Memo1->Lines->Add("用户名:"+AnsiString(aUser.name)); Memo1->Lines->Add("密码:"+AnsiString(aUser.passWord)); Memo1->Lines->Add("计算机名字:"+AnsiString(CInfo.pCName)); Memo1->Lines->Add("IP地址:"+AnsiString(CInfo.pCIP)); Memo1->Lines->Add("MAC地址:"+AnsiString(CInfo.nWMak)); Memo1->Lines->Add("端口号:"+AnsiString(CInfo.port)); } catch (Exception &e) { Memo1->Lines->Add("读取登录信息异常"); } } __finally { delete Strm; }}//---------------------------------------