Base implementation for new protocol

Step 2 of n in the new protocol (#81)

This implements the first parts of the new protocol described by #118. At this point, it's all new code, and is not used in any way. It's compiled by adding `DEFINES+=PROTOCOL_NEW` to the qmake command, but it won't change behavior at all.

Please review carefully and point out anything that seems fragile.
There are two things in conflict here.

     "All pending data to write will be sent"

and

     "it may take up to 5 seconds for the socket to be fully closed"

The internet, at the best of times, is not predictable. Either you're imposing a hard deadline of 5 seconds, or you're waiting until everything is written. Which is it?