Ruby part of the socket refactoring.
WIP Untested modifications to work with TCP connections
Finish the switch to sockets.