예제 #1
0
        public void Disconnect()
        {
            allTrackers.Remove(this);

            OnTrackerDelete?.Invoke(this, new EventArgs());

            if (Status == TrackerStatus.Connected)
            {
                var message = new PeerDisconnectMessage(CommonHelpers.GetLocalEndPoint(CommonHelpers.PeerPort, true));
                try
                {
                    Connection.SendObject(message.GetType().Name, message);
                }
                catch { }
            }

            Task.Run(() =>
            {
                try
                {
                    Connection?.Dispose();
                    Connection = null;
                }
                catch { }
            });

            Status = TrackerStatus.Disconnected;

            CommonHelpers.LogTrackers(allTrackers);
        }
예제 #2
0
        public void DisconnectAny(bool sendMessage = true)
        {
            allPeers.Remove(this);

            CommonHelpers.LogPeers(allPeers);

            try
            {
                if (sendMessage)
                {
                    var message = new PeerDisconnectMessage(CommonHelpers.GetLocalEndPoint(CommonHelpers.PeerPort));

                    if (ConnectionMode == ConnectionMode.Direct)
                    {
                        Connection.SendObject(message.GetType().Name, message);
                    }
                    else
                    {
                        tracker.SendMessageToPeer(message, this);
                    }
                }

                Task.Run(() =>
                {
                    try
                    {
                        Connection?.Dispose();
                        Connection = null;
                    }
                    catch { }
                });
            }
            catch { }

            Status = PeerStatus.Disconnected;
        }