how to detect server closed abnormally,
-
hi all, I am having non-blocking TCP socket, trying to receive in a loop for requried bytes. I am disconnectiing server by removing n/w cable from m/c running server application. every time recv() fails with WSAWOULDBLOCK, why? How can i detect that server died abnormally at client end? recv() also not returning 0? following is code iMode = 1; // non-zero = non-blocking mode iResult = ioctlsocket(sockMain,FIONBIO,(u_long FAR*)&iMode); iDataGot=0; while ( iData2Recv >= iDataGot ) { // recv single byte at a time iResult = recv(sockMain,&chData,1,0); // if zero byte got or any other error if ( iResult == 0 ) { //never reach here break; } /* timeout scheme // check timeout period DWORD dwCur = GetTickCount(); if ( dwCur > dwTimeout ) { // timeout occured, so we failed break; } */ if ( iResult == SOCKET_ERROR ) { if ( WSAGetLastError() != WSAEWOULDBLOCK ) { // never reaches here break; } else { // always executed. continue; } } // we got something add into output string if ( iResult == 1 ) { // add data,update counter into string and break if all datalen is received. } client application calls receive() after 10sec and it timeouts after 10sec if no data arrived. I want eliminate later 10sec. and detect server has died. Thanks in advance.
Jetli Constant Thing In World Is Change.