Added code for initial handshake and code to check internet connection.