timeout problem
-
Hey, this is my code:
connect(s, (SOCKADDR\*) &addrin, sizeof(addrin)); send(s, stRequest.c\_str(), stRequest.length(), 0); cout << "stRequest sent." << endl; recv(s, buffer, sizeof(buffer), 0); cout << "buffer received." << endl;
Now this works perfectly fine if the webserver is working well, but sometimes it just sits there trying to recv() forever.. Iam not exactly sure what causes it but either way, I need a way to set a timeout or something similiar.. I couldn't really find something helpfull on google, so yea I thought maybe you guys could help me out.
-
Hey, this is my code:
connect(s, (SOCKADDR\*) &addrin, sizeof(addrin)); send(s, stRequest.c\_str(), stRequest.length(), 0); cout << "stRequest sent." << endl; recv(s, buffer, sizeof(buffer), 0); cout << "buffer received." << endl;
Now this works perfectly fine if the webserver is working well, but sometimes it just sits there trying to recv() forever.. Iam not exactly sure what causes it but either way, I need a way to set a timeout or something similiar.. I couldn't really find something helpfull on google, so yea I thought maybe you guys could help me out.
You can use WSARecv or an overlapped socket. http://support.microsoft.com/kb/181611[^]
«_Superman_» _I love work. It gives me something to do between weekends.
-
Hey, this is my code:
connect(s, (SOCKADDR\*) &addrin, sizeof(addrin)); send(s, stRequest.c\_str(), stRequest.length(), 0); cout << "stRequest sent." << endl; recv(s, buffer, sizeof(buffer), 0); cout << "buffer received." << endl;
Now this works perfectly fine if the webserver is working well, but sometimes it just sits there trying to recv() forever.. Iam not exactly sure what causes it but either way, I need a way to set a timeout or something similiar.. I couldn't really find something helpfull on google, so yea I thought maybe you guys could help me out.
ALLERSLIT wrote:
Now this works perfectly fine if the webserver is working well, but sometimes it just sits there trying to recv() forever.. Iam not exactly sure what causes it but either way, I need a way to set a timeout or something similiar..
There are multiple choices: - adjust the send/receive timeouts with setsockopt(), see
SO_SNDTIMEO
andSO_RCVTIMEO
- use non-blocking/asynchronous sockets, makes event based applications so much easier - use a C++ networking library/API offering timeouts or search for a HTTP client class, would be my recommendation
Happy coding! :)Chat in Europe :java: Now with 24% more Twitter
modified on Friday, November 19, 2010 8:40 PM