SimpleProtocol
A very simple header-and-body protocol.
Originally written as an example in a Node API doc.
Usage
var sp = ;var Incoming = spIncoming;var Outgoing = spOutgoing; // throw some tcp in there, just for funsies// Note that we have to use allowHalfOpen, because we're not// explicitly managing the sockets, and we want to not close// when we get a FIN from the client.// In a real live environment, you'd probably want a client that can// pool and reuse connections, do keepAlive, etc., and you'd then// want to turn off allowHalfOpen, because the server is not// interested in what the client has to say after it's finished// sending the response.;
And the output goes like:
SERVER header { hello: 'alice', this: 'is bob' }
SERVER message "this is body chunks. and it will stream and stream\nbecause there is no I in example.\n"
SERVER end
CLIENT header { well: 'that was fun' }
CLIENT message "ok, goodbye, now"
CLIENT end
Compatibility
If you want to use this with node v0.8 and before, you'll need to also
install the readable-stream
module. It's not added as a dependency,
because the future is larger than the past.