Moved handshake out of the main TCP message loop.