Пример #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();
        }
Пример #2
0
 public async Task RemovePeer(AsyncPeer peer, int type, object payload = null)
 {
     if (_peers.TryRemove(peer.PeerId, out _))
     {
         await peer.Send(type, payload).ConfigureAwait(false);
     }
 }
Пример #3
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 _);
        }