Re: how to handle socket timeout?



In article
<45b2a0bb-cc60-4a45-8aa3-8b62ed7b6636@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Arkadiy <vertleyb@xxxxxxxxx> wrote:

Hi all,

My client code connects a TCP socket, and then uses it to send
requests and recieve responces many times. What should I do when I
get a timeout? The examples I saw so far seem to suggest to continue
using the socket, however somehow I doubt this is correct, at least in
my case.

If recv() times out, this just means socket didn't get readable -- no
data in the TCP buffer. This doesn't necessarily mean this data won't
appear in this buffer after the timeout have happened. So, if I
continue using the socket, and send another request, the next response
I get (if I get it) will be to my old request...

recv() doesn't time out by default. So if you don't know what to do
about a timeout, don't use the SO_RECVTIMEO option in the first place.


So, my options would be to either keep track of the number of timed-
out requests, so that I can discard correct number of responses, or re-
create and re-connect the socket.

Or just wait for the response and process it when you get it, rather
than timing out.

Is this correct? Am I missing something?

The full answer is that it depends on the application protocol you're
implementing.


Also, with UDP, my server in its responce echoes the request ID that I
send. If I just discard the datagrams with request ID that doesn't
match, will it handle the timeout?

Again, it depends on the application. If you only care about the
response to the most recent request, this will work. But if you
pipeline requests, you may need to process all the responses even if
they arrive out of order.

--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.



Relevant Pages

  • problem WebRequest and WebResponse
    ... I have a problem using HttpWebRequest so I wish somebody can help me. ... HttpWebRequest request = ... WebResponse response = null; ... connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: problem WebRequest and WebResponse
    ... HttpWebRequest request = ... WebResponse response = null; ... System.Net.Sockets.SocketException: A connection attempt failed ... connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: WebRequest.Timeout bugs?
    ... I've found that if the server accepts the request, ... but we thought that by putting a timeout on the ... > response due to the way our authentication works. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Socket mit Network-Byte-Order (Motorola-Format)- Client und Server
    ... Der Fehlerfall ist z.b. ein Timeout? ... sprich Request -> Response ... Step 2: ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: how to handle socket timeout?
    ... Actually I do want rather short timeout. ... Or just wait for the response and process it when you get it, ... response to the most recent request, ... IMO not be using TCP for this, ...
    (comp.unix.programmer)