这篇文章需要技术复核。如何帮忙。
这篇文章需要文法复核。如何帮忙。
翻译正在进行中。
WebSockets 是一种先进的技术, 这使得在用户的浏览器和一个服务器之间打开一个的交互式通信会话成为可能, 有了这个API,你可以向服务器发送消息,并接收事件驱动的响应, 无需轮询服务器的响应。
接口
WebSocket
- 用于连接的WebSocket服务器的主要接口, 然后在连接上发送和接收数据。
CloseEvent
- 当连接关闭时,由WebSocket对象发送该事件。
MessageEvent
- 当从服务器接收到的消息时 ,由WebSocket 对象发送该事件。
工具
- Socket.IO: 一个强大的跨平台的 Node.js WebSocket API.
- WebSocket-Node: 一个 Node.js WebSocket 服务器 API 实现.
- Total.js: Node.js Web 应用框架 (示例: WebSocket chat)
- Faye: 可供 Node.js 客户端和服务器使用的 WebSocket (双向连接) 和 EventSource (单向连接) 实现.
- SignalR: SignalR将使用WebSockets在幕后当它可用,并优雅地回退到其他技术与技术时,它不是,而你的应用程序代码保持不变。
相关话题
另见
浏览器兼容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Version -76 support | 6 | 4.0 (2.0) | 未实现 | 11.00 (disabled) | 5.0.1 |
Protocol version 7 support | 未实现 | 6.0 (6.0) Moz |
未实现 | 未实现 | 未实现 |
Protocol version 10 support | 14 | 7.0 (7.0) Moz |
HTML5 Labs | ? | ? |
Standard - RFC 6455 Support | 16 | 11.0 (11.0) | 10 | 12.10 | 6.0 |
Usable in Workers | (Yes) | 37.0 (37.0) | ? | ? | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Version -76 support | ? | ? | ? | ? | ? |
Protocol version 7 support | ? | ? | ? | ? | ? |
Protocol version 8 support (IETF draft 10) | ? | 7.0 (7.0) | ? | ? | ? |
Standard - RFC 6455 Support | 4.4 | 11.0 (11.0) | ? | 12.10 | 6.0 |
Usable in Workers | (Yes) | 37.0 (37.0) | ? | ? | ? |
Gecko 注意事项
为了符合 WebSocket 规范, Firefox 对 WebSockets 的支持是在持续进行中的. Firefox 6 实现了版本 7 的底层协议, 而 Firefox 7 则实现了版本 8 (在 IETF 草案 10 中提出). Firefox mobile 版本则在 7.0 开始支持 WebSocket.
Gecko 6.0
Prior to Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3), there was, incorrectly, a WebSocket
object that some sites were thinking implied that WebSocket
services were not prefixed; this object has been renamed to MozWebSocket
.
Gecko 7.0
Starting in Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4), the network.websocket.max-connections
preference is used to determine the maximum number of WebSocket connections that can be open at a time. The default value is 200.
Gecko 8.0
Starting in Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5), the deflate-stream extension to the WebSocket protocol has been disabled, since it's been deprecated from the specification drafts. This resolves incompatibilities with some sites.
Gecko 11.0
Prior to Gecko 11.0, both incoming and outgoing messages were limited to 16 MB in size. They may now be up to 2 GB in size. Note, however, that memory limitations (especially on mobile devices) make that a theoretical maximum, not a practical one. In reality, transfers of that size will fail on devices that don't have enough memory.
Additionally, ArrayBuffer send and receive support for binary data has been implemented.
Starting in Gecko 11.0, the WebSocket API is no longer prefixed.