8
HTTP is a blocking, synchronous protocol. This means that the client has to wait for a response from the server before it can continue. The server blocks the clients from doing anything; because the client has to wait for the response to come through. Once the response is received by the browser, the connection is dropped and then another connection is opened and the process repeats till all the elements of the page have been fetched to be displayed.
HTTP是一种阻塞的同步协议。这意味着客户端必须等待服务器的响应才能继续。服务器阻止客户端做任何事情;因为客户必须等待响应才能通过。一旦浏览器收到响应,连接就会被删除,然后打开另一个连接并重复该过程,直到获取了页面的所有元素以进行显示。
This is the state of the web, and the nature of the HTTP protocol.
这是Web的状态,以及HTTP协议的本质。
Ajax simply creates a background process that does what the browser would have done - it is still blocking, but the end effect is that the user can still interact with the client. The browser is displaying something and is not effectively "blocked".
Ajax只是创建一个后台进程来完成浏览器所做的事情 - 它仍然是阻塞的,但最终结果是用户仍然可以与客户端进行交互。浏览器正在显示某些内容,但未被有效“阻止”。
The "realtime" web allows you to have an open socket that is non-blocking, asynchronous. Asynchronous means that you don't have to wait for the response to come back - the client isn't blocked. You can send off multiple requests, and then when the server is done with them, it will respond back. You don't have to "wait".
“实时”Web允许您拥有一个非阻塞,异步的开放套接字。异步意味着您不必等待响应返回 - 客户端未被阻止。您可以发送多个请求,然后当服务器完成它们时,它将回复。你不必“等待”。
Many things you use everyday are asynchronous:
你每天使用的很多东西都是异步的:
- Any chatting application - like IRC, facebook messenger, whatapp, etc.
任何聊天应用程序 - 如IRC,facebook messenger,whatapp等。
- A telephone conversation with a really chatty friend (typically, you would wait to hear the other person's response, but some people just talk and talk...).
与一个非常健谈的朋友进行电话交谈(通常,你会等到听到对方的回应,但有些人只是说话和谈话......)。
- Anything that is streaming, like YouTube.
任何流媒体,如YouTube。
Think of it as simply "one side doesn't have to wait to start transmitting again".
把它简单地想象为“一方不必等待再次开始传输”。
In web, realtime is enabled by getting around the limitations of HTTP. This is where WebSockets and Server sent events (SES) come in.
在Web中,通过绕过HTTP的限制来实现实时。这是WebSockets和Server发送事件(SES)的用武之地。
The first is a standard way of opening a full-duplex (that is, you can send and receive at the same time) channel over TCP.
第一种是通过TCP打开全双工(即,您可以同时发送和接收)信道的标准方法。
The second (SES) is still being standardized as part of HTML5 but it allows the server to push notifications to the client instead of the client having to poll the server for events. So instead of you sending a request to check for updates, the server will tell you when there is an update - like "don't call me, I'll call you".
第二个(SES)仍然被标准化为HTML5的一部分,但它允许服务器将通知推送到客户端,而不是客户端必须轮询服务器以查找事件。因此,不是您发送检查更新的请求,服务器会告诉您何时有更新 - 例如“不要打电话给我,我会打电话给您”。