extract the client connection code into a service