rewrite and refine socket.io connection to server