4
votes

Some of my friends are designing a game, and I am helping them out by implementing the game's backend server. The game is written in Flash, and I plan to develop the server in node.js because (a) it would be a cool project for learning node.js, and (b) it's fast, which is important for games.

The server's architecture is based on messages sent between the server and client (sort of like Minecraft's server protocol). The message format I have so far is a byte (the packet type), two bytes (the message length) and that many bytes (the message data, which is a mapping of key-value pairs). Problem is, I really don't want to develop my own serialization format (because while I probably could, implementing it would be a pain compared to using an existing solution).

Unfortunately, I am having problems finding a good candidate for the message data serialization format.

  • ActionScript's own remoting format might work, but I don't like it much.
  • JSON has support in node.js (obviously) and in ActionScript, but it's also textual and I would prefer binary for enhanced speed.
  • MessagePack looked like a good candidate, but I can't find an ActionScript implementation. (There's one called as3-msgpack on Google Code, but I get weird errors and can't access it.)
  • BSON has an ActionScript implementation, but no node.js support besides their MongoDB library (and I'm planning on using Redis).

So, can anyone offer any other serialization formats that I might have missed? Or should I just stick with one of these (or roll my own)?

5

5 Answers

1
votes

Isn't that why HTTP supports gzipped content? Just use JSON and gzip the content when you send it. The time spent gzipping is more than recovered by the reduced latency of the transmission.

Check this article for more on gzip with Actionscript. On node.js I think that gzip-compress is fairly popular.

1
votes

Actually, if I were in your shoes I would implement two methods and time them. Use JSON because it is common and easy to do. But then implement AMQP instead and compare them. If you want to massively scale this then you might find that AMQP makes it easier. Also. message queuing is just such a nice fit into the node.js world view.

AMQP on Actionscript, and someone doing similar on node.js.

0
votes

If you wanted to, you could create your entire API in client side JavaScript, and use JSON as the data exchange format, then call ExternalInterface by AS to communicate with the client JavaScript API, which would make for an elegant server side solution.

It is worth noting that Flash Player has built in support for decompressing gzip compressed data. It may be worth compressing some of your JSON objects, things like localised string tables, game configuration data, etc which can grow to be a few hundred kb but are only loaded once on game load.

0
votes

I'm working on a version of MessagePack for AS3. At the current version it does the basic (encoding/decoding). Planning streams for the future. Check the project page: https://github.com/loteixeira/as3-msgpack