RFC 6455-The WebSocket Protocal部分内容

Posted Rogn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RFC 6455-The WebSocket Protocal部分内容相关的知识,希望对你有一定的参考价值。

1. Web的基本数据帧格式:

WebSocket在建立连接之后,通信的基本数据格式如下图(来源RFC6455-5.2),没有Http请求那么多固定的报文,且不用重复建立连接,所以通信效率高:

 

2. Websocket是如何管理连接的?

RFC6455-5.5给出了答案,协议定义了Control Frame。

WebSocket的控制帧有:Close、Ping、Pong。其中Close是发起关闭请求;Ping是通信发起方确认链路是否畅通的报文;Pong是通信接收方回应链路是否畅通的报文。

对应数据帧中的opcode位(Close 0x8, Ping 0x9, Pong 0xA).

3. Http与Websocket的区别与联系:

Http与websocket是两个完全不同的协议,都是基于TCP的。两者唯一的联系是WebSocket利用Http进行握手;具体说明请看RFC6455-1.7

1.7.  Relationship to TCP and HTTP

   _This section is non-normative._

   The WebSocket Protocol is an independent TCP-based protocol.  Its
   only relationship to HTTP is that its handshake is interpreted by
   HTTP servers as an Upgrade request.

   By default, the WebSocket Protocol uses port 80 for regular WebSocket
   connections and port 443 for WebSocket connections tunneled over
   Transport Layer Security (TLS) [RFC2818].

 

以上是关于RFC 6455-The WebSocket Protocal部分内容的主要内容,如果未能解决你的问题,请参考以下文章

Websocket框架,TCP段:关系?

web socket RFC6455 frame 打包解包

Websocket RFC 中的这个数据帧示例如何等于“Hello”?

Websocket 无故断开并出现 1006 错误

c++ websocket帧发送导致服务器关闭连接

WebSocket学习