Socket的怪问题
我用ClientSocket 和 ServerSocket做连接,出现了这样一种情况,
每次启动连接的时候,都要ConnectButton Click 两次才能连接得上,我是在本机上测试的,不存在网络延迟的问题啊,程序代码是这样的:
if(ServerEdit->Text != ""&& NumEdit->Text != "" && PswEdit->Text != "")
{
DataModule1->ClientSocket->Address = ServerEdit->Text;
DataModule1->SocketConnect->Address = ServerEdit->Text;
MESSAGE_TO* msg = new MESSAGE_TO;
msg->num = StrToInt(NumEdit->Text);
msg->require = REQUIRE_LOGIN;
strcpy(msg->text ,PswEdit->Text.c_str());
try
{
DataModule1->ClientSocket->Open();
DataModule1->ClientSocket->Socket->SendBuf(msg,sizeof(MESSAGE_TO));
if(DataModule1->ClientSocket->Active)//就是在里了,非要第2次连接才能通过
{
LogButton->Enabled = false;
delete msg;
}
}
catch(...)
{
MessageBox(NULL,"连接服务器失败","出错信息",MB_OK|MB_ICONERROR);
delete msg;
}
}
else MessageBox(NULL,"登陆验证数据不完整","错误信息",MB_OK|MB_ICONERROR);
why??????????????????????????????????