I'm building a multiplayer game in HTML5. I've done some reading on sending binary data through WebSockets via ArrayBuffers like Uint8Array as I'm like to avoid as much overhead as possible (so no JSON). However, I'm still lost on how to actually send specific variable types (especially 1 bit Booleans) through the WebSocket.
For example, I want to send 5 booleans and 3 numbers (precision to be determined later) via binary data in 1 message (so no multiple sends). In this case:
How would I approach this? Could I put it all into a Uint8Array? Isn't that a byte? What if I only need say 5 bits and not 8, would it still take up 8? How do append booleans to and extract booleans from the ArrayBuffer? Or am I using the wrong approach altogether?
Thanks for the help.
you can use DataView which is more easy to use to write data stream.