Formatting WebSocket中\x00和\xff的含义是什么?

Formatting WebSocket中\x00和\xff的含义是什么?,formatting,message,websocket,Formatting,Message,Websocket,为什么通过WebSocket发送的消息总是以\x00开头,以\xff结尾,就像在\x00您的消息\xff中一样?我不是100%确定这一点,但我的猜测可能意味着消息的开始和结束。由于x00是0的单字节表示,而xFF是255的单字节表示,这可能有助于 摘自第1.2节:- Data is sent in the form of UTF-8 text. Each frame of data starts with a 0x00 byte and ends with a 0xFF byte,

为什么通过WebSocket发送的消息总是以
\x00
开头,以
\xff
结尾,就像在
\x00您的消息\xff
中一样?

我不是100%确定这一点,但我的猜测可能意味着消息的开始和结束。由于x00是0的单字节表示,而xFF是255的单字节表示,这可能有助于

摘自第1.2节:-

   Data is sent in the form of UTF-8 text.  Each frame of data starts
   with a 0x00 byte and ends with a 0xFF byte, with the UTF-8 text in
   between.

   The WebSocket protocol uses this framing so that specifications that
   use the WebSocket protocol can expose such connections using an
   event-based mechanism instead of requiring users of those
   specifications to implement buffering and piecing together of
   messages manually.

   To close the connection cleanly, a frame consisting of just a 0xFF
   byte followed by a 0x00 byte is sent from one peer to ask that the
   other peer close the connection.

   The protocol is designed to support other frame types in future.
   Instead of the 0x00 and 0xFF bytes, other bytes might in future be
   defined.  Frames denoted by bytes that do not have the high bit set
   (0x00 to 0x7F) are treated as a stream of bytes terminated by 0xFF.
   Frames denoted by bytes that have the high bit set (0x80 to 0xFF)
   have a leading length indicator, which is encoded as a series of
   7-bit bytes stored in octets with the 8th bit being set for all but
   the last byte.  The remainder of the frame is then as much data as
   was specified.  (The closing handshake contains no data and therefore
   has a length byte of 0x00.)

工作规范已更改,不再使用0x00和0xFF作为开始和结束字节


我不确定,但大多数字符串系统都是以null结尾的,null是\x00,您是否可以从另一个角度看到它?(ie:Your message\xff\x00)感谢您的评论。