0

I'm playing around with websockets using socket.io. I've made a chat room, but I want to make a real time game. The socket.io docs say that any data type can be sent over websockets, so I'm wondering what the most efficient data type would be for sending data like player position, velocity, and keypress information.
In other words, in games like agar.io and whatnot, what type of data is really being sent between the client and server? Is it binary, json, etc.?

Caleb Bertrand
  • 410
  • 5
  • 15

2 Answers2

0

If you are coding in JavaScript just use JSON you will have to convert it back anyways otherwise. If there is some bigger data like pictures you can think about streaming it, have a look at https://www.npmjs.com/package/socket.io-stream.

ju_
  • 569
  • 1
  • 4
  • 17
0

The most efficient way to send data packets is binary. Agar.io and most of other web games also use this. You can give every packet an different OPCODE at index 0 to differentiate between packets.

Sidshash
  • 45
  • 5