refactory remoting socket handling.