Is a persistent http connection (keep-alive), always bound to a specific port, or can it use a range of ports?


When a client opens a HTTP connection to a web server, it allocates a local socket from the operating system, which binds the socket to some port on the originating server. This is the source port of the connection, and it can be basically anything (different OSes have limits on ports though).

The other end of the socket is connected to web server port 80 (default HTTP) or custom web server port. This port is the same for all connections to that particular web server.

Keep-alive mechanism works simply so that the client (web browser) nor server does not close the TCP connection immediately after the request has been fulfilled, keeping the connection open in case new requests need to be made.

Therefore, the same source / destination ports apply for the keepalive connection.

If there is no traffic on the connection for specified time, either end can close the TCP connection.

Next request to the server will then make a new connection, opening a new source port.


The connections are just to the normal HTTP listener, if that's what you mean - it's not a separate listening port.

As far as what ports it can use, HTTP is normally on port 80, but you can set your HTTP server up on any port you wish.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.