Handle disconnects better.

Close the socket when a disconnect is explicitly requested, and have
the example script request a disconnect when Ctrl-C'd.