Search code examples
network-programmingtcp

What happens to the connections that have been established when a service stops listening on that TCP port?


Can you describe the main process with TCP connection status?

In fact I'm more concerned about whether those connections that have been established can be closed after the client receives a proper reply from the server ...... That's part of the graceful shutdown, I think.


Solution

  • The accepted connections are totally independent of the listening socket. So the server can stop listening and the accepted sockets can still be used as if nothing happened. This means that each accepted socket has it's own tcp connection state (diagram).

    Often, though, servers stop listening when they are shut down, so they close all sockets at that time.