httpwebsocketutf-8dataformat

How does this data frame example in the Websocket RFC equal “Hello”?


The first example of Section 5.7 of Websocket Protocol RFC 6455 reads:

A single-frame unmasked text message

  • 0x81 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains "Hello")

What are the first two octets in this example and why are they there?

Looking up the UTF-8 codes for the last five octets I can see how those bytes would translate to Hello.


Solution

  • The first two octets in this example contain metadata about the data frame and the payload it contains. The last five octets represent the payload or Hello.

    The first two octets 0x81 0x05 are hexadecimal representations of two bytes or 16 bits of data. In binary they translate to: 1000 0001 0000 0101.

    Using the Data Frame Diagram from the RFC you can see what these bits tell us about the data frame. To summarize: