奇怪的问题,idudp 控件,怎么点击两次按钮才生效.
client 端点击连接服务器,其中Clients 是自定义的结构,记录client信息,然后发给server:
struct Clients
{
char Name[20];//client 主机名
char Ip[15];//IP地址
} ;
void __fastcall TForm2::ConnectClick(TObject *Sender)
{
Clients * Clt=new Clients;
strcpy(Clt->Name,Client->LocalName.c_str());
strcpy(Clt->Ip,GStack->LocalAddress.c_str());
Client->Port=StrToInt(Edit2->Text);
Client->Active=true;
Client->SendBuffer(Clt,sizeof(Clients)); //发送
delete Clt;
}
server端 onread事件:
void __fastcall TForm1::ServerUDPRead(TObject *Sender, TStream *AData,
TIdSocketHandle *ABinding)
{
Clients * Clt=new Clients;
char* Msg;
String Astring="welcome you";
Server->ReceiveBuffer(Clt,sizeof(Clients));//接收 发来的client信息,
Memo1->Lines->Add(Clt->Name); //Memo里显示,
Memo1->Lines->Add(Clt->Ip);
delete Clt;
}
奇怪的是第一次点击connect按钮,Memo里无字符,再次点击显示正确,这个控件爱吃回头草,郁闷啊!