Socket destination is now localhost rather than server hostname, to
remove delay caused by DNS lookup.
Fixed resource leak, where sockets were not being closed.