Exemplo n.º 1
0
        public async Task Start(IPAddress address, int bindPort = 9050)
        {
            if (_alive)
            {
                throw new Exception("Cannot start, client is running");
            }

            var socket = new Socket(address.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
            {
                NoDelay = true
            };
            await socket.ConnectAsync(new IPEndPoint(address, bindPort)).ConfigureAwait(false);

            _alive = true;

            Peer = new AsyncPeer(socket);

            try
            {
                await Peer.Process().ConfigureAwait(false);
            }
            catch { }

            ShutDown();
        }
Exemplo n.º 2
0
        private async Task ProcessSocket(Socket socket)
        {
            var peer = new AsyncPeer(socket);

            _peers.TryAdd(peer.PeerId, peer);

            try
            {
                await peer.Process().ConfigureAwait(false);
            }
            catch { }

            _peers.TryRemove(peer.PeerId, out _);
        }