Move portions of socket code to RemoteNode.
Added a mutex to the main method.