Example #1
0
        void ScanClientControl()
        {
            long current = DateTimeExtensions.CurrentTimeMillis();

            foreach (KeyValuePair <int, ClientControl> ccItem in ClientTable)
            {
                ClientControl clientControl = ccItem.Value;
                if (clientControl != null)
                {
                    if (current - clientControl.LastReceivePingTime < ReceivePingTimeout &&
                        current - clientControl.LastReceivePingTime > SendPingInterval)
                    {
                        clientControl.SendPingPacket();
                    }
                }
                else
                {
                    //Timtout
                    Console.WriteLine("Timeout and close client: "
                                      + clientControl.DstHost + ":" + clientControl.DstPort
                                      + " " + DateTime.Now.ToString());

                    lock (SynClientTable)
                    {
                        clientControl.Close();
                    }
                }
            }
        }
Example #2
0
        public ClientControl GetClientControl(int clientId, string dstHost, int dstPort)
        {
            ClientControl clientControl = ClientTable[clientId];

            if (clientControl == null)
            {
                clientControl = new ClientControl(MyRoute, clientId, dstHost, dstPort);

                lock (SynClientTable)
                {
                    ClientTable.Add(clientId, clientControl);
                }
            }
            return(clientControl);
        }
Example #3
0
        public ConnectionUDP GetConnection2(string dstHost, int dstPort, int connectId, int clientId)
        {
            ConnectionUDP conn = ConnTable[connectId];

            if (conn == null)
            {
                ClientControl clientControl = MyClientManager.GetClientControl(clientId, dstHost, dstPort);
                conn = new ConnectionUDP(this, dstHost, dstPort, 2, connectId, clientControl);

                lock (this)
                {
                    ConnTable.Add(connectId, conn);
                }
                clientControl.AddConnection(conn);
            }
            return(conn);
        }
Example #4
0
        public ConnectionUDP(Route route, string dstHost, int dstPort,
                             int mode, int connectId, ClientControl clientControl)
        {
            MyClientControl = clientControl;
            MyRoute         = route;
            DstHost         = dstHost;
            DstPort         = dstPort;
            Mode            = mode;
            ConnectId       = connectId;

            try
            {
                MySender   = new Sender(this);
                MyRecevier = new Receiver(this);
                Uos        = new UDPOutputStream(this);
                Uis        = new UDPInputStream(this);

                /*
                 * if (mode == 2)
                 * {
                 *  route.CreateTunnelProcessor().Process(this);
                 * }
                 */
            }
            catch (Exception e)
            {
                _connected = false;
                route.ConnTable.Remove(connectId);

                lock (this)
                {
                    Monitor.PulseAll(this);
                }
                throw (e);
            }
        }