Can I reuse a TCP connection?
I'm connecting to a website and retrieving HTTP data by sending i开发者_如何学Pythont a GET request. And I have to connect to the same site twice to retrieve two different pages. I'm new to network programming but I believe the connect
function connects to the server, and creates a tcp connection.
Now each time I connect to the server to retrieve the HTTP data, it has to create a new tcp connection, is there any way I can reuse the old one? It's retrieving the http data immediately after the other. It's not that big of a deal but I'm curious.
You could use HTTP 1.1
where connection are persistent or use HTTP 1.0 and send the header "Connection: Keep-Alive".
That way you can fetch a second page without connecting again (just GET
again on the same socket).
精彩评论