Online Whiteboard Server
In order to have a full-fledged online whiteboard, I needed some kind of server to handle all the message passing. I tried writing the simplest possible server I could think of. Out of that came what seems to be a generally useful and flexible server.
Conceptually, the server is sending and receiving hashes. It keeps track of the state changes so it only needs to send the latest updates to each client.
For example, if you’ve got a “dog” entity, it might look like this:
dog = {
:name => “Darcy”,
:breed => “corgie”
:weight => 50,
:color => “brown”,
:poop => “smelly”,
:mood => “happy”,
}
The name and breed aren’t likely to change, but if darcy the dog see’s a squirrel, you might send an update:
dog_update = {
:mood => “crazy excited”
}
This is very similar to how general object systems work, e.g.:
databases have create/read/update/delete
The hashes and hash_updates are sent via json just because flash happens to have an existing json library [link to json library]. If bandwidth were a concern, you could add compression or do an “on the fly binary conversion” [link to packet optimizer format]. In order to identify the objects being sent around, there’s a global and local id associated with each entity. Both the client and server have information to map the id’s back and forth.
Looking back on this, it seems like I’ve just accidentally built a database cache. Oops. I guess that’s a project for another time though: adding a real database.