Refactoring to SocketEventHandler and SocketErrorHandler