Socket dispatcher/handler. JS socket wrapper