Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

JoeZhang

HELP! Winsock problem about the select function...

This topic is 5127 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, guys, In my current Winsock-based TCP program, on the client side, after I send my request data packet to the Server side using the send socket function, I attempt to get the socket status to see if it has something to read using the select function, and the select function always return 0 meaning the time limit expired on some users'' computers, but it''s just fine on another users'' computers. Why? Does anybody can tell me why and how to fix it? Thanks! here''s the code... //... SOCKET sckClient = socket(AF_INET, SOCK_STREAM, 0); int nOne = 1; setsockopt(sckClient, IPPROTO_TCP, TCP_NODELAY, (char *)&nOne, sizeof(int)); // just_say_no struct sockaddr_in addr_to = { 0 }; //... connect(sckClient, (struct sockaddr *)&addr_to, sizeof(addr_to)); char *buf; //... send(sckClient, (const char *)((char*)buf), nDataToSend, 0); int nRetCode = ::select((int)sckClient + 1, &fdsRead, NULL, NULL, &tvTimeOut); if (nRetCode==0 ) { //ERROR: the time limit expired //Here''s the problem! some computers meet the error, but some don''t! WHY??? } recv(sckClient,(char *)buf,nDataToRead, 0); //...

Share this post


Link to post
Share on other sites
Advertisement
Use WSAAsyncSelect() instead. That way your wndproc gets a notification every time something happens.
I think the Mudpies-tutorial here on Gamedev goes through the usage of them...

Share this post


Link to post
Share on other sites
Greetings

What did you set the tvTimeOut value to be?

tvTimeOut.tv_sec = 0; // Seconds
tvTimeOut.tv_usec = 250000; // micro-seconds

// The above times out after quarter of a second

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!