Improve socket and ping handling