怎樣判斷socket斷開并自動(dòng)重連?
這樣行不行:
if(receive.Connect(sip,6000)!=0)
{
intret;
while(TRUE)
{
ret=receive.Receive(buff,10,0);
if(ret==0)//連接關(guān)閉
{
if(receive.Connect(sip,6000)==0)//重新連接
{
break;//連不上不再連接
}
}
elseif(ret==socket_ERROR)
{
AfxMessageBox("連接錯(cuò)誤");
receive.Close();
break;
}
}
}