websocket 、stomp关系

来源:互联网 发布:网络课影视鉴赏答案 编辑:程序博客网 时间:2024/05/22 05:01

项目已经用websocket的时间很长了,但是只会用,并不知道这其中的关系。
今天看到spring refernce中解释如下

WebSocket does imply a messaging architecture but does not mandate the use of any specific messaging protocol. It is a very thin layer over TCP that transforms a stream of bytes into a stream of messages (either text or binary) and not much more. It is up to applications to interpret the meaning of a message.

Unlike HTTP, which is an application-level protocol, in the WebSocket protocol there is simply not enough information in an incoming message for a framework or container to know how to route it or process it. Therefore WebSocket is arguably too low level for anything but a very trivial application. It can be done, but it will likely lead to creating a framework on top. This is comparable to how most web applications today are written using a web framework rather than the Servlet API alone.

For this reason the WebSocket RFC defines the use of sub-protocols. During the handshake, the client and server can use the header Sec-WebSocket-Protocol to agree on a sub-protocol, i.e. a higher, application-level protocol to use. The use of a sub-protocol is not required, but even if not used, applications will still need to choose a message format that both the client and server can understand. That format can be custom, framework-specific, or a standard messaging protocol.

The Spring Framework provides support for using STOMP — a simple, messaging protocol originally created for use in scripting languages with frames inspired by HTTP. STOMP is widely supported and well suited for use over WebSocket and over the web.

三言两语说下他们的关系,websocket协议因为其包体包含信息较少,所以并不像是HTTP那样包含了很多的信息,他就是一串简单的文本, 而stomp协议可以解决这个问题。并且支持比较广泛。

具体可以参考官网
http://stomp.github.io/stomp-specification-1.2.html