Use a connection subclass to manage the socket

Change-Id: If9f688c3f33a824bd5685d32e613ee531d3463e8