什么是长轮询,Websocket,服务器发送事件(SSE)和Comet?

一曲冷凌霜 提交于 2020-08-05 02:34:05

问题:

I have tried reading some articles, but I am not very clear on the concepts yet. 我已经尝试阅读一些文章,但是我对这些概念还不太清楚。

Would someone like to take a shot at explaining to me what these technologies are: 有人想向我解释一下这些技术是什么吗?

  1. Long Polling 长轮询
  2. Server-Sent Events 服务器发送的事件
  3. Websockets 网络套接字
  4. Comet 彗星

One thing that I came across every time was, the server keeps a connection open and pushes data to the client. 我每次遇到的一件事是,服务器保持打开连接并将数据推送到客户端。 How is the connection kept open, and how does the client get the pushed data? 连接如何保持打开状态,客户端如何获取推送的数据? (How does the client use the data, maybe some code might help?) (客户端如何使用数据,也许一些代码可能会有所帮助?)

Now, which one of them should I use for a real-time app. 现在,我应该为实时应用程序使用哪一个。 I have been hearing a lot about websockets (with socket.io [a node.js library]) but why not PHP? 我已经听到很多关于websockets的信息(使用socket.io [一个node.js库]),但是为什么不使用PHP?


解决方案:

参考一: https://stackoom.com/question/kTr7/什么是长轮询-Websocket-服务器发送事件-SSE-和Comet
参考二: https://oldbug.net/q/kTr7/What-are-Long-Polling-Websockets-Server-Sent-Events-SSE-and-Comet
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!