lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Reconnect issue


From: Kieran Mansley
Subject: Re: [lwip-users] Reconnect issue
Date: Thu, 14 Jul 2011 16:09:47 +0100

On Thu, 2011-07-14 at 16:26 +0200, Per Klint wrote:
> Any ideas why this behaves differently in 1.4.0?

I'm not sure why there is a difference in behaviour between those
versions.  The delay is due to the TCP time wait state.  You can shorten
this by changing the define that sets the default time to wait in that
state, but I would recommend reading up on what that state is for before
making that decision.

The problem is caused because the accepted socket shares the same local
port number as the listening socket, and so while the accepted socket
still exists (albeit in time wait) you can't create the listener.

You can also avoid it by changing the way that the client and server
interact.  As a listener, your application is normally deemed to be a
server, and if the client (rather than the server) closes the socket
first the server will not go through the time wait state.  I.e. it is
the end that calls close() first on a socket that will go through time
wait.  The other end will not.  This is often used in client/server
implementations to avoid time wait states on the server.  This isn't
specific to lwIP, and should be the same on all TCP implementations.

SO_REUSEADDR should be another way to avoid the problem.  If that's not
working for you I would investigate that.

Finally, you could also work around it by not repeatedly closing and
re-opening the listening socket.  Just leave it open and don't accept
things (or even remove it from your select set) when you're not ready to
handle another connection.

Kieran




reply via email to

[Prev in Thread] Current Thread [Next in Thread]