Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSocket protocol binary data endianness

I am writing server and client based on WebSocket protocol.

Server is made using Python and Twisted.

Right now I can send binary data from server to client and back, only problem is that, according to some sources, endianness of binary data sent from browser is based on machine endianness. I want to make sure, is it true?

If it's true, then should I somehow check what endianness client has and read/send data from/to him using his endianness? What is the best way to check client endianness, just send from client

var view_buffer = new UInt8Array(new ArrayBuffer(1));
view_buffer[0] = 1;

this data, and check on server if it returns 1 or 128?

like image 925
Rafał Łużyński Avatar asked Jan 31 '13 21:01

Rafał Łużyński


1 Answers

According to RFC 6455:

Multibyte length quantities are expressed in network byte order.

Network byte order is big endian. Both the server and the client should use this byte order, no matter what their native order is.

In Python the struct module can be used to ensure the proper byte order with the '>' specifier. I'm not sure how it would be done in Javascript.

like image 165
Mark Ransom Avatar answered Oct 04 '22 09:10

Mark Ransom