WebSocket+STOMP+SockJS

来源:互联网 发布:unity3d资源包 编辑:程序博客网 时间:2024/05/14 08:56

WebSocket

https://www.w3.org/TR/websockets/

The WebSocket protocol defines two types of messages, text and binary, but their content is undefined. It’s expected that the client and server may agree on using a sub-protocol (i.e. a higher-level protocol) to define message semantics. While the use of a sub-protocol with WebSocket is completely optional either way client and server will need to agree on some kind of protocol to help interpret messages.

WebSocket sub-protocols

the WebSocket RFC defines the use of sub-protocols
https://tools.ietf.org/html/rfc6455#section-1.9

STOMP

STOMP is a simple text-orientated messaging protocol.
STOMP is widely supported and well suited for use over WebSocket and over the web.

STOMP是一种简单的消息协议,非常合适用作WebSocket的子协议
http://jmesnil.net/stomp-websocket/doc/

SockJS

https://github.com/sockjs/sockjs-client

使用SockJS作为客户端,当浏览器不支持websocket时,会使用长轮询等方式。

The SockJS client begins by sending “GET /info” to obtain basic information from the server. After that it must decide what transport to use. If possible WebSocket is used. If not, in most browsers there is at least one HTTP streaming option and if not then HTTP (long) polling is used.

Chrome 可以在引用sockjs文件前禁用websocket,从而看到长轮询的效果。

window.WebSocket = null;
原创粉丝点击