Re: The "Reconnect" Problem



Michael B Allen <miallen@xxxxxxxxxx> writes:

[...]

Let's say I'm writing a networking client and I would like to multiplex
requests over the same connection. Everything works great and it's
all very efficient but when the connection gets dropped for whatever
reason (e.g. I pull the network cable out of the computer) and I want to
reconnect transparently, there is a tendency for the code to get caught
in an endless loop of disconnect and connect ops.

I solved a similar problem with this approach:

The connection is managed in a dedicated thread. This thread tries to
connect when a connection is desired, and when it is connected
processes a queue of pending requests to be sent. When the connection
is up a second thread sits in a blocking read on the connected socket.
Clients that want to send messages put them into a queue. The
connection thread will wake up when there is a message in the queue,
try to connect if necessary, then send the message. Clients can
register callbacks to handle incoming data, and to be notified when
their message has been succesfully sent.

So the API becomes "send", which enqueues a message to be sent,
connecting if necessary and retrying if necessary; and
"register_recv_callback" which registers a callback to handle incoming
messages.

Hope this helps,

----Scott.
.



Relevant Pages

  • Re: Context Switches, Web Gardens and InProc Session State
    ... serialized and therefore we cannot use StateServer for the Session mode. ... the requests are routed back to the same worker process." ... Are your clients connecting via a proxy or firewall, ... That said its not possible to guarantee a fixed connection. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Asynchronous socket server
    ... Create a listener thread the accepts connection. ... you don't even need the queue or locking on it. ... | threads can pass data to or communicate with the asynchonous socket server ... | send data back to the clients. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Connecting Out of Process Servers via COM+
    ... connection, and in fact we can only use one connection because of the way ... years ago when I needed a number of clients to share a single serial ... it would create a Dispatcher-Object first and registers ... > This means, altough COM+ would allow parallel requests, the calls would be ...
    (microsoft.public.vb.com)
  • Re: output.c error in multithreaded program
    ... >>I find an access violation windows message and start the JIT debugger to ... > thread will block until the Sleep() expires, ... >>it a good enough approach to handle repeated requests. ... connection. ...
    (microsoft.public.vc.mfc)
  • Slow DNS requests?
    ... I think that the delay is in resolving the DNS requests. ... Guest machines connected via CAT5 to the BEFSR41 run fine. ... As soon as the host name is resolved, performance seems to improve dramatically for that connection. ... It offers one set of entries for "Name Servers" and a different set for "Domain Search". ...
    (comp.os.linux.networking)