A generic JSON message processor

This generalises what is currently implemented in the server for handling JSON messages over TCP sockets. 

Currently it doesn't really handle socket errors. Like, at all. The correct way to handle these cases (which are marked as comments in `process` and `flushSendQueue`) will become more apparent when we actually start using it.

Edit; almost forgot: :8ball: