connecting to endpoint and handling requests to and from endpoint