簡體   English   中英

重用HTTP的客戶端TCP連接

[英]Reusing Client TCP Connection for HTTP

為什么不調用close(http_socket_fd) ,為什么不能在C Web客戶端中重用http客戶端套接字? 第一次對套接字文件描述符的寫入/讀取效果很好。 任何/所有連續讀取均返回零(幾乎沒有錯誤)。

基本上,我不想繼續為同一請求重新創建到同一主機的新客戶端連接套接字。 在C語言中,是否不可能將開放的客戶端套接字(已啟用HTTP保持活動狀態)重新用於連續的讀/寫操作? 使用Java http://www.mail-archive.com/httpclient-dev@jakarta.apache.org/msg04687.html似乎有可能

Example: (PSEUDO_CODE)
MANY_DOMAINS=30,000;
//initial connection
do{
  http_socket_to_domain_x=open(NEW_TCP_SOCKET_PER_DOMAIN);
  get(initial_url_path);
  read(http_socket_to_domain_x,initial_http_response);
} while(EACH_DOMAIN)
for(LIST_OF_URLS FROM EACH_DOMAIN);
  //successive connections - NO RECREATING TCP SOCKET!
do{
  get(another_url_path);
  read(http_socket_to_domain_x,another_http_response);
} while(EACH_URL_PER_DOMAIN)
//finally
close(http_socket_to_domain_x);

您想閱讀持久性HTTP / 1.1連接

服務器可能正在關閉連接。 您是否正在發送HTTP / 1.1標頭? 有關更多信息 ,請參見http://www.io.com/~maus/HttpKeepAlive.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM