Reputation:
I am writing a TCP concurrent server which will fork a child process to deal with every new connection. Suppose ClientA is interacting with ChildA while server is still listening on same port. In case we kill server with say SIGINT signal, ClientA and ChildA keep on interacting.
So, in that situation if I restart my server, it obviously throws Address already in use
on bind
function call.
What are all possible solutions to this issue and which one is usually followed?
Upvotes: 1
Views: 1563
Reputation: 980
2 options.
kill
ChildA processes when server is killed.
close
the fd
used to listen
/bind
in ChildA as soon as the fork
is done.
Upvotes: 2
Reputation: 311023
Set the socket option SO_REUSEADDR
on the listening socket before you bind it.
Upvotes: 1