请教,一个TCP连接,能否连续发送多个HTTP请求?

唐稚骅 2014-09-24 05:33:07
请教,一个TCP连接,能否连续发送多个HTTP请求?

如果客户端可以连续发送多个请求,那么服务器返回的响应可能是乱序。如果是这样,客户端又将如何区分每个响应。

比如,客户端依次发送请求 1 ,2, 3。由于网络原因,服务器收到的请求顺序可能为3, 1, 2。然后服务器一次对每个请求发出响应,响应顺序为3, 1, 2。如果网络正常,那么对于客户端来说,收到的响应顺序将是3, 1, 2.


...全文
1863 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 5 楼 Cody2k3 的回复:
稍微google了一下看来还真有 http://en.wikipedia.org/wiki/HTTP_pipelining HTTP pipelining is a technique in which multiple HTTP requests are sent on a single TCP connection without waiting for the corresponding responses.[1]
呵呵,that sounds like browser end nginx...
Cody2k3 2014-09-25
  • 打赏
  • 举报
回复
稍微google了一下看来还真有 http://en.wikipedia.org/wiki/HTTP_pipelining HTTP pipelining is a technique in which multiple HTTP requests are sent on a single TCP connection without waiting for the corresponding responses.[1]
Cody2k3 2014-09-25
  • 打赏
  • 举报
回复
呵呵我也没有说“同时”啊,看楼主的“连续”做何解
  • 打赏
  • 举报
回复
引用 2 楼 Cody2k3 的回复:
楼主窃以为有三个要点,仅供参考 早期的tcp确实一个connection一个request,不过后来keepalive和persistent tcp connection 已经是标准实现,一个connection一般都会有多个request response的交互 参见 http://en.wikipedia.org/wiki/HTTP_persistent_connection 其次,tcp是保证顺序的投递服务所以不会出现你所说的乱序,如果你使用三个conn来发三个服务倒是有可能由于路由或者掉包重传导致到达顺序随机 再次, 与这个问题稍稍无关, http是无状态协议,所以乱序不应该成为问题,每个request response都应该相对独立
不过后来keepalive和persistent tcp connection 已经是标准实现 tcp requests are still sent in sequential order even in persistent mode. I don't think one connection can handles multiple requests at the same time, can it?
Cody2k3 2014-09-25
  • 打赏
  • 举报
回复
楼主窃以为有三个要点,仅供参考 早期的tcp确实一个connection一个request,不过后来keepalive和persistent tcp connection 已经是标准实现,一个connection一般都会有多个request response的交互 参见 http://en.wikipedia.org/wiki/HTTP_persistent_connection 其次,tcp是保证顺序的投递服务所以不会出现你所说的乱序,如果你使用三个conn来发三个服务倒是有可能由于路由或者掉包重传导致到达顺序随机 再次, 与这个问题稍稍无关, http是无状态协议,所以乱序不应该成为问题,每个request response都应该相对独立
唐稚骅 2014-09-25
  • 打赏
  • 举报
回复


HTTP pipelining is a technique in which multiple HTTP requests are sent on a single TCP connection without waiting for the corresponding responses.
Dobzhansky 2014-09-25
  • 打赏
  • 举报
回复
tcp 连接一次, 完成多次 http 请求, 是完全可以的, 现在浏览器都是复用连接的, 你可以用 tcpview 看一下.
qq120848369 2014-09-25
  • 打赏
  • 举报
回复
TCP是有序的,httpd处理request也是有序的。
  • 打赏
  • 举报
回复
You might have to do some reading on network models/protocols first... http is on application level of OSI, TCP is 3 levels below at Transport layer. On top of transport layer, there is the session layer, where u can find sockets, which provides connection-oriented communication between two network endpoints that guarantees data is delivered in the same order as it was sent. It takes advantage of TCP at the transport layer. This mechanism achieves in-order delivery of a byte-stream, by means of segment sequence numbering on the sender side, packet buffering and data packet reordering on the receiver side. The sequence numbering requires two-way synchronization of segment counters during a three-step connection establishment phase. The transmission is also reliable because this sequence number is included on each transmitted packet, and acknowledged by the opposite host as an acknowledgement number to inform the sending host that the transmitted data was received successfully. feel too much? I told you...take your time...

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧