java - how to work out payload size from html5 websocket -
how can tell html5 message payload length on websockets?
im aware base protocol consists of op code, length determine next 1 8 bytes, following values hashing , rest payload!
im creating java serverside application receivea message html5 client , handle, ii can handle messages 256 bytes.
any work out manually great (i.e how habdle bytes determine payload)
cheers
there 3 ways how payload length of websocket frame can encoded, depend on length of payload:
- 125 or less
- 126-65535
- 65536 +
which way used can told looking @ value of 7 last bits of 2nd byte (the first bit of 2nd byte masking flag).
when it's below 126, it's payload length. when it's 126, payload length in following 2 bytes. when it's 127, payload length in following 8 bytes.
so algorithm have follow interpret websocket frame is:
- read 1st byte ("
byte0") fin flag , opcode - read 2nd byte ("
byte1") - when
byte1greater 127, subtract 127byte1, setmaskedtrue - when
byte1126, read next 2 bytes , convertshort.payload_length. - when
byte1127, read next 8 bytes , convertlong.payload_length. - when
byte1else,payload_lengthequal value ofbyte1 - when
maskedtrue, read next 4 byte.masking_key. - read number of bytes have in
payload_lengthpayload. - when
maskedtrue, applymasking_keypayload.
there no hash-code in websocket frame, must have mixed up. integrity of websocket frame ensured tcp layer beneath it.
for more information websocket protocol, refer rfc 6455.
Comments
Post a Comment