added generic support for connecting to socket