make sure socket exists before calling a method on it