Better error handling for the socket server