network: implemented the connect function.