| |

VerySource

 Forgot password?
 Register
Search
Author: weekice

Questions about ending threads

[Copy link]

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-8-15 21:15:02
| Show all posts
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;
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list