windows socket error 10022 on API WSACANCELASYNCREQUEST
以下是TIME控件里的代码..SocketClient的数量是根据配置文件中的数据动态创建的.创建完成后会与服务器进行连接.
以下代码均是在服务器没有运行的情况下测试....
void __fastcall TfrmShow::tmrSendTimer(TObject *Sender)
{
tmrSend->Enabled = false;
for(int i = 0;i< n_Btnnum; i++)
{
SocketClient[i]->Host = Buttons[i]->Hint;
SocketClient[i]->Port = m_Port;
int nFlag;
if(SocketClient[i]->Active == false)
SocketClient[i]->Active = true;
nFlag = SocketClient[i]->Socket->SendText("1"); //随便发送消息.服务端收到即可响应
if(nFlag == 0)
{
SocketClient[i]->Active = false;
SocketClient[i]->Socket->Close(); //这句的问题.如果改成SocketClient[i]->Close()就不会出错.但是会导致句柄数无限上升直至用尽.
Image[i]->Picture->LoadFromFile(ExtractFilePath(Application->ExeName) + "\\Image\\close.png");
}
}
tmrSend->Enabled = true;
}
void __fastcall TfrmShow::OnSocketError(TObject *Sender, TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
ErrorCode = 0;
}