Re: implementing a time bound wait on the socket (TCP)




Don't call Socket.Poll().  Ever.  It's just not the right way to implement  
things.  Problems include that you are unnecessarily using the CPU and the  
Poll() method isn't reliable (the Socket may become unreasonable between  
the time Poll() says it's readable and the time you get around to actually  
trying to read it).

Well, I inherited the project from the previous developer used poll,
among other things. The ongoing design on the client side is not in
the best state, and I am trying to sort it out

Correct approaches to the problem involve keeping a separate timer (for  
example, using the System.Threading.Timer class) that performs some  
appropriate action.  If you are looking for a "wait since last read any  
data", then you need to reset the timer each time you actually  
successfully read data.  An appropriate action might be to close the  
socket, but without knowing your specific goals, it's impossible to say  
for sure.

The simplistic version of the protocol: you send a request, via
socket, to the remote application, and it 'immediately' response with
a response in a byte buffer (there are no intentional delays on the
application side). The buffer contains various headers, sub-headers,
and the message. After parsing it, I forward a response to clients via
subscribed events. So client sends many requests, then waits for
responses. I want client to be able to specify how much time to
allocate for the [post] responses before sending additional set of
requests or close the connection.

Also, that assumes that "assuming that nothing else is coming from the  
wire" is a valid approach.  If you have no control over the application  
protocol, maybe that's correct.  But generally speaking, it's a poor way  
to deal with network i/o.  Communications should have a well-defined end,  
so that timeouts aren't required at all.

Any good references you may recommend to design this sort of
applications?

Thanks...



.



Relevant Pages

  • Re: Java socket <-> Dolphin socket problem
    ... XML and processing it correctly and sending the XML response as ... has sent a response to it's side of the socket. ... yet received by the client process (i.e. your Smalltalk ...
    (comp.lang.smalltalk.dolphin)
  • Re: implementing a time bound wait on the socket (TCP)
    ... The ongoing design on the client side is not in ... Whether you wrote it or you inherited it, calling Poll() is still bad. ... a response in a byte buffer (there are no intentional delays on the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "tcpflags 0x18; tcp_do_segment" kernel messages
    ... closed the socket, thus he is not interested in the server's response. ... normal client workflow is to wait for the server's response to the ... are all two servers running -CURRENT, ...
    (freebsd-current)
  • Re: Socket Question
    ... A socket question from a networking newbie. ... check that message and response to it. ... the client get the server message and send another message. ...
    (comp.lang.python)
  • Network Sockets Question
    ... DoSomethingexecutes, it will not "follow through" unless the ... > Then of course your method won't fire until a socket is actually accepted. ... > as the listening socket, you should use the Poll() method, like so: ... the code accepts the client ...
    (microsoft.public.dotnet.languages.csharp)

Quantcast