1
votes

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?

2

2 Answers

2
votes

2 options.

  1. kill ChildA processes when server is killed.

  2. close the fd used to listen/bind in ChildA as soon as the fork is done.

1
votes

Set the socket option SO_REUSEADDR on the listening socket before you bind it.