sockets: connection logic