basic tcp connection logic