超时,也是 返回: SOCKET_ERROR 用WSAGetLastError() 获取 id 再分析,程序如下:
memset(buff,0x0,buff_size); if (recv(sock,buff,sizeof(buff),0) == SOCKET_ERROR){ id = WSAGetLastError(); switch (id) { case WSANOTINITIALISED: printf("not initialized\n"); break; case WSASYSNOTREADY: printf("sub sys not ready\n"); break; case WSAHOST_NOT_FOUND: printf("name server not found\n"); break; case WSATRY_AGAIN: printf("server fail\n"); break; case WSANO_RECOVERY: printf("no recovery\n"); break; case WSAEINPROGRESS: printf("socket blocked by other prog\n"); break; case WSANO_DATA: printf("no data record\n"); break; case WSAEINTR: printf("blocking call canciled\n"); break; case WSAEPROCLIM: printf("limit exceeded\n"); case WSAEFAULT: printf("lpWSAData in startup not valid\n"); default: printf("unknown error id = %d\n",id); break; }; printf("receive error.\n"); };