Javascript 浏览器的 Websocket 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5510537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Websocket library for browsers?
提问by ajsie
Are there websocket libraries (like ajax for jquery) I can use on the browsers with fallback to ajax long polling?
是否有 websocket 库(如 jquery 的 ajax)我可以在浏览器上使用并回退到 ajax 长轮询?
采纳答案by yojimbo87
回答by Chad Johnson
I found that Socket.IO implements a weird, arbitrary layer over the WebSocket protocol. I'd rather just pass raw data back and forth, so for my project, I went with web-socket-js.
我发现 Socket.IO 在 WebSocket 协议上实现了一个奇怪的、任意的层。我宁愿来回传递原始数据,因此对于我的项目,我使用了web-socket-js。
web-socket-js works similarly to Socket.IO in that it reverts to using Flash sockets if WebSocket support is unavailable. Thus, it works in all the major browsers that support Flash (I tested this myself).
web-socket-js 的工作方式与 Socket.IO 类似,因为如果 WebSocket 支持不可用,它会恢复使用 Flash 套接字。因此,它适用于所有支持 Flash 的主要浏览器(我自己测试过)。
Just make sure you open port 843 in your firewall or you'll get a Flash security policy error. You'll probably need a script to listen on port 843 as well...I used em-websocket for the socket server, and in its readme I believe is a link to a Perl script that provides this.
只需确保在防火墙中打开端口 843,否则您将收到 Flash 安全策略错误。您可能还需要一个脚本来侦听端口 843 ……我将 em-websocket 用于套接字服务器,在它的自述文件中,我相信是提供此功能的 Perl 脚本的链接。
回答by Chad Johnson
I have been using SignalR for the last several months, and it is awesome. It does what Socket.IO does, but maybe even better. It degrades as follows: Web Sockets, Server Sent Events, Forever Frame, AJAX long polling. Only works with .NET though.
过去几个月我一直在使用 SignalR,它很棒。它做 Socket.IO 做的事,但也许更好。它降级如下:Web 套接字、服务器发送的事件、永久帧、AJAX 长轮询。不过只适用于 .NET。
回答by Peter Lubbers
Yes, you'll need server support for that as well. Kaazing WebSocket Gateway supports a very fast emulation/Polyfill. If you have a plugin like Flash it may use that (opportunistic optimization), but if you don't it emulates WebSocket with encrypted streaming, which is a lot more efficient than long polling. It comes with SSE and Cross Document Messaging support and emulation as well, as well as many higher level protocol abstractions (JMS/Stomp, XMPP, etc.)
是的,您也需要服务器支持。Kaazing WebSocket 网关支持非常快速的仿真/Polyfill。如果你有一个像 Flash 这样的插件,它可能会使用它(机会优化),但如果你不使用它,它会模拟带有加密流的 WebSocket,这比长轮询效率高得多。它还带有 SSE 和跨文档消息传递支持和仿真,以及许多更高级别的协议抽象(JMS/Stomp、XMPP 等)
回答by colin moock
Union Server has WebSocket support with fallback to comet-style AJAX communication. Union is a platform for creating connected applications, such as online multiplayer games.
Union Server 具有 WebSocket 支持,可回退到彗星式 AJAX 通信。Union 是一个用于创建连接应用程序的平台,例如在线多人游戏。