I'm trying to reduce socket.io
bandwidth when using websockets. I switched to binary data, but looking in the browser developer console, the packets are sent as:
[ 'type of the packet (first argument of .emit)', associated data ]
I'm using only one packet type, so this causes unnecessary overhead - useless bytes are sent and whole thing is json encoded for no reason.
How can I get rid of the packet type and just send raw data?
socket.io
is an abstraction on top ofwebSocket
. In order to support the features it provides, it adds some overhead to the messages. The message name is one such piece of that overhead since it is a messaging system, not just a packet delivery system.If you want to squeeze all bytes out of the transport, then you probably need to get rid of
socket.io
and just use a plain webSocket where you control more of the contents of each packet (though you will have to reimplement some things that socket.io does for you).With socket.io in node.js, you can send binary by sending an ArrayBuffer or Buffer. In the browser, you can send binary by sending an ArrayBuffer or Blob.