是否可以在 WebSockets 中使用具有所需端口(例如 6500)的 http 方案而不是 ws 和 wss 方案?
我想知道
是否有任何方法可以使用 http://
方案而不是 ws://
或 wss://
HTML5 中的 Websockets
方案,如果没有那么为什么不呢?
在 HTML5 中声明 Websocket 并使用自定义协议有哪些不同的方法?
I would like to know,
if there is any way possible to use http://
scheme instead of ws://
or wss://
schemes for Websockets
in HTML5, if not then why not?
What are the various ways to declare Websockets in HTML5 and using custom protocols?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。但服务器应该响应
Connection:upgrade
然后切换到 WebSocket 协议。除非您代理该请求。它将使用 HTTP CONNECT 来维护隧道,但其想法是 WebSocket 流量使用 WebSocket 协议。 (参考)MDN 中的该页面是草稿,不应用作参考。这是相当不完整的。
如果您正在考虑开发 WebSocket 客户端/服务器,请查看 socket.io。这是一个相当完善的实现,带有后备功能。
Yes. But the server is supposed to respond with
Connection: upgrade
and then switch to the WebSocket protocol. Unless you're proxying the request. It'll useHTTP CONNECT
to maintain a tunnel, but the idea is that WebSocket traffic uses the WebSocket protocol. (reference)That page from MDN is draft and shouldn't be used as reference. It's rather incomplete.
Have a look at socket.io if you're thinking about doing a WebSocket client/server. It's a rather well built implementation with fallback.