/// <summary>
        /// Connects to a peer in the peer-to-peer network. If the remote end point resides behind the same firewall as the current application,
        /// a direct connection to the local peer is made, for improved performance.
        /// </summary>
        /// <param name="RemoteEndPoint">Remote End-point.</param>
        /// <returns>Peer connection</returns>
        public async Task <PeerConnection> ConnectToPeer(IPEndPoint RemoteEndPoint)
        {
            if (this.State != PeerToPeerNetworkState.Ready)
            {
                throw new IOException("Peer-to-peer network not ready.");
            }

            BinaryTcpClient Client          = new BinaryTcpClient();
            IPEndPoint      RemoteEndPoint2 = RemoteEndPoint;

            try
            {
                RemoteEndPoint2 = this.CheckLocalRemoteEndpoint(RemoteEndPoint);
                await Client.ConnectAsync(RemoteEndPoint2.Address, RemoteEndPoint2.Port, true);
            }
            catch (Exception ex)
            {
                Client.Dispose();
                System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw();
            }

            PeerConnection Result = new PeerConnection(Client, this, RemoteEndPoint2, this.encapsulatePackets);

            Result.StartIdleTimer();

            return(Result);
        }
Esempio n. 2
0
        /// <summary>
        /// Connect to the remote host and port using a binary protocol over TCP.
        /// </summary>
        /// <param name="Sniffers">Sniffers</param>
        /// <returns>Binary TCP transport.</returns>
        public async Task <BinaryTcpClient> ConnectTcp(params ISniffer[] Sniffers)
        {
            BinaryTcpClient Client = new BinaryTcpClient(Sniffers);
            await Client.ConnectAsync(this.Host, this.port);

            return(Client);
        }