HELP! Winsock problem about the select function...
-
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); //...
-
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); //...