socket句柄用尽 不能执行套接字上的操作.
程序用临时创建了几个clientsocket.然后定时向服务端发送数据
void __fastcall TfrmShow::tmrSendTimer(TObject *Sender)
{
tmrSend->Enabled = false;
for(int i = 0;i< n_Btnnum; i++)
{
AnsiString sStr = SocketClient[i]->Host;
SocketClient[i]->Port = m_Port;
if(SocketClient[i]->Active == false)
SocketClient[i]->Active = true;
SocketClient[i]->Socket->SendText("1"); //随便发送消息.服务端收到即可响应
}
tmrSend->Enabled = true;
}
void __fastcall TfrmShow::OnSocketError(TObject *Sender, TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
in_addr inaddr;
inaddr = Socket->Addr.sin_addr;
AnsiString sAddr = inet_ntoa(inaddr);
//出现的均是通讯有问题的数据.
for(int i = 0;i< n_Btnnum; i++)
{
if(iledZsd[i]->Hint == sAddr)
{
Image[i]->Picture->LoadFromFile(ExtractFilePath(Application->ExeName) + "\\Image\\close.png");
//同时关闭此socket.防止用尽句柄
SocketClient[i]->Close();
SocketClient[i]->Active = false;
}
}
ErrorCode = 0;
}