且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JS/HTML5 WebSocket:无需 HTTP 调用即可连接

更新时间:2022-06-25 05:08:15

没有.建立连接后,您将拥有一个真正的套接字.但你是对的,它需要特殊的服务器支持.所以它不会让你连接到未经修改的 POP 或 IMAP 服务器.

No. Once the connection is established you have a true socket. But you're right that it requires special server support. So it won't let you connect to an unmodified POP or IMAP server.

他们选择了这种设计(升级机制),以便您可以轻松地拥有一个侦听 WebSocket 连接以及真正的 HTTP 请求的服务器.

They chose that design (the Upgrade mechanism) so you could easily have a server that listened for WebSocket connections as well as true HTTP requests.

与 AJAX 和 COMET 仍有很大区别.您可以使用 WebSockets 在服务器和客户端之间进行真正的全双工通信.以前的浏览器 API 没有提供这一点,迫使人们使用各种变通方法(例如重复的 AJAX 请求、COMET 的永久框架等).

There is still a big distinction from AJAX and COMET. You can use WebSockets to have true full-duplex communication between server and client. Previous browser APIs haven't provided that, forcing people to use various work-arounds (such as repeated AJAX requests, COMET's forever frame, and others).