Search code examples
tcptcpclient

Length of a TCP socket's life


Is it better to keep a TCP socket open for a long time, or re-establish connection frequently?

Let's take HTTP in a browser as an example. Is it better to establish a connection, make the HTTP request, and upon receiving a response, close it only to open a new one when we make a new request? Or: Should you keep the socket open for as long as that particular user is still browsing that specific site?


Solution

  • There is no problem with leaving a socket open. Keep alive option is meant for this. I'll leave it open.