Exemplo n.º 1
0
 public void Disconnect(object socket, int timeout)
 {
     if (socket != null)
     {
         if (ToPeer.ContainsKey((EndPoint)socket))
         {
             if (SocketList.Contains(ToPeer[(EndPoint)socket]))
             {
                 SocketList.Remove(ToPeer[(EndPoint)socket]);
             }
         }
         if (SocketToKey.ContainsKey((EndPoint)socket))
         {
             SocketToKey.Remove((EndPoint)socket);
         }
         if (ToPeer.ContainsKey((EndPoint)socket))
         {
             ToPeer.Remove((EndPoint)socket);
         }
         lock (checklock)
         {
             if (clientcheck.ContainsKey((EndPoint)socket))
             {
                 clientcheck.Remove((EndPoint)socket);
             }
         }
     }
 }
Exemplo n.º 2
0
        public void Close()
        {
            lock (SendLock)
            {
                if (listener != null)
                {
                    try
                    {
                        listener.Shutdown(SocketShutdown.Both);
                    }
                    finally
                    {
                        listener.Close();
                        listener = null;
                    }
                }

                StopThread();

                SocketList.Clear();
                Packets.Clear();
                ToPeer.Clear();
                SocketToKey.Clear();
                clientcheck.Clear();
                OnListenClient.Clear();

                GetMessage = null;

                RSAkey = new EncryptAndCompress.RSAKeyPair();
            }
        }
Exemplo n.º 3
0
        public void Close()
        {
            if (listener != null)
            {
                try
                {
                    listener.Shutdown(SocketShutdown.Both);
                }
                catch (Exception) { }
                finally
                {
                    listener.Close();
                    listener = null;
                }
            }

            SocketList.Clear();
            Packets.Clear();
            ToPeer.Clear();
            SocketToEndPoint.Clear();
            SocketToKey.Clear();

            GetMessage = null;

            RSAkey = new EncryptAndCompress.RSAKeyPair();
        }
Exemplo n.º 4
0
        public void ConnectSuccessful(Func <object, INetServer, PeerBase> AddPeerFunc, Packet packet)
        {
            SocketToKey.Add(packet.peer, (string)packet.state);
            PeerBase peer = AddPeerFunc(packet.peer, this);

            SocketList.Add(peer);
            SocketToEndPoint.Add(((Socket)packet.peer), ((Socket)packet.peer).RemoteEndPoint);
            ToPeer.Add(((Socket)packet.peer).RemoteEndPoint, peer);

            using (Packet newpacket = new Packet(packet.peer))
            {
                packet.BeginWrite(PacketType.CONNECT_SUCCESSFUL);
                packet.WriteSendData(new SendData(0, "On Connect"), (string)packet.state, EncryptAndCompress.LockType.AES);
                Send(packet, packet.peer);
            }
        }
Exemplo n.º 5
0
        public void Disconnect(object socket, int timeout)
        {
            if (socket != null)
            {
                if (SocketToEndPoint.ContainsKey((Socket)socket))
                {
                    if (ToPeer.ContainsKey(SocketToEndPoint[(Socket)socket]))
                    {
                        if (SocketList.Contains(ToPeer[SocketToEndPoint[(Socket)socket]]))
                        {
                            SocketList.Remove(ToPeer[SocketToEndPoint[(Socket)socket]]);
                        }
                    }
                    if (SocketToKey.ContainsKey(socket))
                    {
                        SocketToKey.Remove(socket);
                    }
                    if (ToPeer.ContainsKey(SocketToEndPoint[(Socket)socket]))
                    {
                        ToPeer.Remove(SocketToEndPoint[(Socket)socket]);
                    }
                }

                try
                {
                    ((Socket)socket).Shutdown(SocketShutdown.Both);
                }
                catch (Exception e)
                {
                    GetMessage(e.Message);
                }
                finally
                {
                    if (timeout == -1)
                    {
                        ((Socket)socket).Close();
                    }
                    else
                    {
                        ((Socket)socket).Close(timeout);
                    }
                    socket = null;
                }
            }
        }