From: novickivan on
I have a server process that listens for incoming connections on a
specific port.

If the server is killed or dies it does not properly close the socket
and when trying to restart the server it takes about 60 seconds before
the server will be allowed to bind to this socket again.

Is there any way to avoid this delay in rebinding to the socket. I
noticed other well known servers don't have this issue so there should
be some solution.

Thanks and regards,
Ivan Novick
http://www.mycppquiz.com
From: Ian Collins on
novickivan(a)gmail.com wrote:
> I have a server process that listens for incoming connections on a
> specific port.
>
> If the server is killed or dies it does not properly close the socket
> and when trying to restart the server it takes about 60 seconds before
> the server will be allowed to bind to this socket again.
>
> Is there any way to avoid this delay in rebinding to the socket. I
> noticed other well known servers don't have this issue so there should
> be some solution.

Use the SO_REUSEADDR option to setsockopt to enable the port to be reused.

See the setsockopt man page.

--
Ian Collins
From: novickivan on
On Sep 4, 5:49 pm, Ian Collins <ian-n...(a)hotmail.com> wrote:
> novicki...(a)gmail.com wrote:
> > Is there any way to avoid this delay in rebinding to the socket.  I
> > noticed other well known servers don't have this issue so there should
> > be some solution.
>
> Use the SO_REUSEADDR option to setsockopt to enable the port to be reused..

Very cool Thanks!!

Ivan Novick
http://www.mycppquiz.com
 | 
Pages: 1
Prev: mblk
Next: fork() then clean up