简体   繁体   English

请求响应处理是否在http服务器中异步完成?

[英]Is request response processing done asynchronously in http server?

I am trying to implement an http server in Java, I have a very basic(silly) doubt. 我正在尝试用Java实现http服务器,我有一个非常基本的(傻)疑问。 Does the request response processing happen asynchronously ? 请求响应处理是否异步发生? If so, then how does client decide which response is for which request? 如果是这样,那么客户如何确定对哪个请求的响应? Suppose a client fires 3 separate GET requests, when it receives a response , how does it decide this response was for which request? 假设客户端触发3个单独的GET请求,当它收到响应时,如何确定此响应是针对哪个请求的? Do I need to manage the session /state in client as well as server side? 我需要管理客户端以及服务器端的会话/状态吗? Any pointers are much appreciated. 非常感谢任何指针。

With HTTP 1.x it is simple: the first response inside the TCP connection is for the first request, the second response for the second request. 使用HTTP 1.x很简单:TCP连接中的第一个响应用于第一个请求,第二个响应用于第二个请求。 If you have multiple TCP connections in parallel the happens for each of them, ie it is not possible to send a request on one connection and receive the response on the other. 如果并行有多个TCP连接,则每个连接都会发生,即,不可能在一个连接上发送请求,而在另一个连接上接收响应。

With SPDY or HTTP 2.0 it is slightly different because request/response can be interleaved inside the same TCP connection. 使用SPDY或HTTP 2.0时,它稍有不同,因为可以在同一TCP连接中交错请求/响应。 But this is all handled by the protocol so that it looks more like several virtual connections inside the same TCP connection where all inhibit the same behavior as described with HTTP 1.x. 但这都是由协议处理的,因此看起来更像是同一TCP连接中的多个虚拟连接,其中所有虚拟连接都禁止使用HTTP 1.x中所述的相同行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM