是否可以在 WebSockets 中使用具有所需端口(例如 6500)的 http 方案而不是 ws 和 wss 方案?

发布于 2024-12-24 21:18:01 字数 196 浏览 1 评论 0原文

我想知道

是否有任何方法可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

向地狱狂奔 2024-12-31 21:18:01

是的。但服务器应该响应 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 use HTTP 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文