Re: implementing a time bound wait on the socket (TCP)
- From: puzzlecracker <ironsel2000@xxxxxxxxx>
- Date: Mon, 20 Oct 2008 13:43:46 -0700 (PDT)
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...
.
- Follow-Ups:
- Re: implementing a time bound wait on the socket (TCP)
- From: Peter Duniho
- Re: implementing a time bound wait on the socket (TCP)
- References:
- implementing a time bound wait on the socket (TCP)
- From: puzzlecracker
- Re: implementing a time bound wait on the socket (TCP)
- From: Peter Duniho
- implementing a time bound wait on the socket (TCP)
- Prev by Date: Re: Declare array size in Struct?
- Next by Date: Re: Generics, constrains and inheritance
- Previous by thread: Re: implementing a time bound wait on the socket (TCP)
- Next by thread: Re: implementing a time bound wait on the socket (TCP)
- Index(es):
Relevant Pages
|