|
Sorry, the front is not Receive, it should be .recv(); I heard that it is caused by blocking mode, how to solve it
Solution:
Set it to timeout.
The following is for reference only:
int **::ConnectService( )//Connect function
{
sockClient=socket(AF_INET,SOCK_STREAM,0 );
//unsigned long ul = 1;
//int nRet = ioctlsocket(sockClient, FIONBIO, (unsigned long*)&ul);
int TimeOut=60000; //Set the sending timeout for 6 seconds
if(::setsockopt(sockClient,SOL_SOCKET,SO_SNDTIMEO,(char *)&TimeOut,sizeof(TimeOut))==SOCKET_ERROR){
return 1;
}
TimeOut=60000;//Set the receiving timeout 6 seconds
if(::setsockopt(sockClient,SOL_SOCKET,SO_RCVTIMEO,(char *)&TimeOut,sizeof(TimeOut))==SOCKET_ERROR){
return 1;
}
addrSrv.sin_addr.S_un.S_addr=inet_addr( m_serverIP );
addrSrv.sin_family = AF_INET;
addrSrv.sin_port = htons( m_serverPort );
connect_return=connect(sockClient,(SOCKADDR*)&addrSrv,sizeof( SOCKADDR ));
return connect_return;
} |
|