I’m makinga Java server for the last version of the draft. I managed to make the connection, and that’s working great.
The problem is that I don’t understand how the data is encoded, I’ve been trying to find some example of how it has to be done but I couldn’t find anything. so I’m trying to do it by myself but need some help.
Here is an image of the frame.
But I don’t understand where the payload begins. What is:
Extended payload length (16/63) (if payload len==126/127)
That’s the place where my payload should be?
Can someone give some help because as you may see, I’m completely lost…
The problem is that the length does not always fit in 7 bits (you can only express the numbers 0 to 127 with 7 bits), and in that case either the following 2 or 8 bytes will be used to make the length fit:
So the payload starts at either index 2, 4 or 10, if not encoded. When encoded, it starts at either 6, 8 or 14 (because there are 4 mask bytes).
I previously posted some pseudocode about decoding the payload data.
To actually get the length as a “real number” (instead of separate bytes), you can use bitwise shift operators as follows (in case there are two bytes for the length):
This will calculate it like this:
Suppose:
bytes[2]is01101001(105in base 10)bytes[3]is10100101(165in base 10)Then
<<will be doing:|is basically adding them:So if you have the bytes
105and165, then they represent a length of27045.