开发者

Can I reuse a TCP connection?

开发者 https://www.devze.com 2023-04-10 07:39 出处:网络
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

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消