繁体   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