RFC6455-The WebSocket protocol 之七:6. Sending and Receiving Data

2024-09-02 05:18

本文主要是介绍RFC6455-The WebSocket protocol 之七:6. Sending and Receiving Data,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

6.  Sending and Receiving Data

6、发送和接收数据


6.1.  Sending Data

6.1 发送数据
   To _Send a WebSocket Message_ comprising of /data/ over a WebSocket
   connection, an endpoint MUST perform the following steps.

在WebSocket连接上发送一个包含数据的WebSocket信息,终端必须执行以下的步骤。

   1.  The endpoint MUST ensure the WebSocket connection is in the

 OPEN
       state (cf. Sections 4.1 and 4.2.2.)  If at any point the state of
       the WebSocket connection changes, the endpoint MUST abort the
       following steps.

1、终端必须确保WebSocket连接处于OPEN状态,如果在任何时间WebSocket连接的状态发生了变化,终端必须终止后续操作。


   2.  An endpoint MUST encapsulate the /data/ in a WebSocket frame as
       defined in Section 5.2.  If the data to be sent is large or if
       the data is not available in its entirety at the point the
       endpoint wishes to begin sending the data, the endpoint MAY
       alternately encapsulate the data in a series of frames as defined
       in Section 5.4.

终端需要把数据封装到一个WebSocket数据包中。终端计划去发送数据的时候,如果发送的数据太大或作为一个整体有问题,终端可能会把数据封装到一系列的数据包中。


   3.  The opcode (frame-opcode) of the first frame containing the data
       MUST be set to the appropriate value from Section 5.2 for data
       that is to be interpreted by the recipient as text or binary
       data.

包含数据的第一个数据包的操作码必须设置合理,从而接收者可以对文本或二进制数据进行正确的解析。


   4.  The FIN bit (frame-fin) of the last frame containing the data
       MUST be set to 1 as defined in Section 5.2.

最后一个数据包的FIN位必须设置为1。


   5.  If the data is being sent by the client, the frame(s) MUST be
       masked as defined in Section 5.3.

假如数据是客户端发送的,数据包必须进行掩码。


   6.  If any extensions (Section 9) have been negotiated for the
       WebSocket connection, additional considerations may apply as per
       the definition of those extensions.

假如WebSocket连接定义了一些扩展,按照这些扩展的定义会增加一些额外的注意事项。


   7.  The frame(s) that have been formed MUST be transmitted over the
       underlying network connection.

被加工的数据包必须在网络连接上进行传输。


6.2.  Receiving Data

6.2 接收数据
   To receive WebSocket data, an endpoint listens on the underlying
   network connection.  Incoming data MUST be parsed as WebSocket frames
   as defined in Section 5.2.  If a control frame (Section 5.5) is
   received, the frame MUST be handled as defined by Section 5.5.  Upon
   receiving a data frame (Section 5.6), the endpoint MUST note the
   /type/ of the data as defined by the opcode (frame-opcode) from
   Section 5.2.  The "Application data" from this frame is defined as
   the /data/ of the message.  If the frame comprises an unfragmented
   message (Section 5.4), it is said that _A WebSocket Message Has Been
   Received_ with type /type/ and data /data/.  If the frame is part of
   a fragmented message, the "Application data" of the subsequent data
   frames is concatenated to form the /data/.  When the last fragment is
   received as indicated by the FIN bit (frame-fin), it is said that _A
   WebSocket Message Has Been Received_ with data /data/ (comprised of
   the concatenation of the "Application data" of the fragments) and   type /type/ (noted from the first frame of the fragmented message).
   Subsequent data frames MUST be interpreted as belonging to a new
   WebSocket message.
   Extensions (Section 9) MAY change the semantics of how data is read,
   specifically including what comprises a message boundary.
   Extensions, in addition to adding "Extension data" before the
   "Application data" in a payload, MAY also modify the "Application
   data" (such as by compressing it).
   A server MUST remove masking for data frames received from a client
   as described in Section 5.3.

为了接收数据,终端需要监听网络连接。传入的数据必须转换成WebSocket数据包的格式。假如接收到了控制数据包,则按照5.5节所述处理。一旦接收到一个数据包,终端需要注意到操作码的内容。数据包中的应用数据是消息的内容。假如数据包是没有分片的信息,接收方会类型、数据一块接收。假如数据包是分片数据的一个,后续的数据包的应用数据组成了完整的数据。假如以FIN位标记的最后一个分片被接收了,就意味着WebSocket消息的数据(各分片中应用数据的和)、类型(分片信息中的第一个分片中)都被接收了。后续的数据包必须被看成是一个新的WebSocket消息。

扩展可能会改变数据如何去读的规则,尤其是包含消息边界的时候。扩展信息,除了会在负载的应用数据之前增加扩展数据之外,还可能修改应用数据(例如压缩它)。服务端必须对从客户端接收到的数据进行解掩码操作。

这篇关于RFC6455-The WebSocket protocol 之七:6. Sending and Receiving Data的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1129097

相关文章

关于WebSocket协议状态码解析

《关于WebSocket协议状态码解析》:本文主要介绍关于WebSocket协议状态码的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录WebSocket协议状态码解析1. 引言2. WebSocket协议状态码概述3. WebSocket协议状态码详解3

Java springBoot初步使用websocket的代码示例

《JavaspringBoot初步使用websocket的代码示例》:本文主要介绍JavaspringBoot初步使用websocket的相关资料,WebSocket是一种实现实时双向通信的协... 目录一、什么是websocket二、依赖坐标地址1.springBoot父级依赖2.springBoot依赖

HTML5 data-*自定义数据属性的示例代码

《HTML5data-*自定义数据属性的示例代码》HTML5的自定义数据属性(data-*)提供了一种标准化的方法在HTML元素上存储额外信息,可以通过JavaScript访问、修改和在CSS中使用... 目录引言基本概念使用自定义数据属性1. 在 html 中定义2. 通过 JavaScript 访问3.

JavaWeb-WebSocket浏览器服务器双向通信方式

《JavaWeb-WebSocket浏览器服务器双向通信方式》文章介绍了WebSocket协议的工作原理和应用场景,包括与HTTP的对比,接着,详细介绍了如何在Java中使用WebSocket,包括配... 目录一、概述二、入门2.1 POM依赖2.2 编写配置类2.3 编写WebSocket服务2.4 浏

SpringBoot实现websocket服务端及客户端的详细过程

《SpringBoot实现websocket服务端及客户端的详细过程》文章介绍了WebSocket通信过程、服务端和客户端的实现,以及可能遇到的问题及解决方案,感兴趣的朋友一起看看吧... 目录一、WebSocket通信过程二、服务端实现1.pom文件添加依赖2.启用Springboot对WebSocket

论文翻译:arxiv-2024 Benchmark Data Contamination of Large Language Models: A Survey

Benchmark Data Contamination of Large Language Models: A Survey https://arxiv.org/abs/2406.04244 大规模语言模型的基准数据污染:一项综述 文章目录 大规模语言模型的基准数据污染:一项综述摘要1 引言 摘要 大规模语言模型(LLMs),如GPT-4、Claude-3和Gemini的快

Java Websocket实例【服务端与客户端实现全双工通讯】

Java Websocket实例【服务端与客户端实现全双工通讯】 现很多网站为了实现即时通讯,所用的技术都是轮询(polling)。轮询是在特定的的时间间隔(如每1秒),由浏览器对服务器发 出HTTP request,然后由服务器返回最新的数据给客服端的浏览器。这种传统的HTTP request 的模式带来很明显的缺点 – 浏 览器需要不断的向服务器发出请求,然而HTTP

CentOS下mysql数据库data目录迁移

https://my.oschina.net/u/873762/blog/180388        公司新上线一个资讯网站,独立主机,raid5,lamp架构。由于资讯网是面向小行业,初步估计一两年内访问量压力不大,故,在做服务器系统搭建的时候,只是简单分出一个独立的data区作为数据库和网站程序的专区,其他按照linux的默认分区。apache,mysql,php均使用yum安装(也尝试

使用Spring Boot集成Spring Data JPA和单例模式构建库存管理系统

引言 在企业级应用开发中,数据库操作是非常重要的一环。Spring Data JPA提供了一种简化的方式来进行数据库交互,它使得开发者无需编写复杂的JPA代码就可以完成常见的CRUD操作。此外,设计模式如单例模式可以帮助我们更好地管理和控制对象的创建过程,从而提高系统的性能和可维护性。本文将展示如何结合Spring Boot、Spring Data JPA以及单例模式来构建一个基本的库存管理系统

15 组件的切换和对组件的data的使用

划重点 a 标签的使用事件修饰符组件的定义组件的切换:登录 / 注册 泡椒鱼头 :微辣 <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-