Exemple #1
0
 void Check_Timer(object state)
 {
     try
     {
         foreach (var i in TCP_Local.UDP_List.ToArray())
         {
             if (!DataHandle.TCP_Usability(i.TCP_Client))
             {
                 i.TCP_Client.Dispose();
                 i.UDP_obj.Dispose();
                 TCP_Local.UDP_List.Remove(i);
             }
         }
     }
     catch (SocketException)
     {
     }
 }
Exemple #2
0
        public TCP_Start(string IP_ADDR, int PORT, string Pass, int Local_PORT)
        {
            ///四项是否为空

            IP             = IP_ADDR;
            DataHandle.Key = DataHandle.Get_Pass(Pass);
            Port           = PORT;
            Local_Port     = Local_PORT;
            if (IP != "" && Keys != "" && Port != 0 && Local_Port != 0)
            {
                tcpListener = new TcpListener(IPAddress.Any, Local_Port);
                tcpListener.Start();
                tcpListener.BeginAcceptTcpClient(Accept_TCP, tcpListener);
                Checker_Timer = new System.Threading.Timer(Check_Timer, null, 0, 1000 * 5);
                state         = true;
            }
            else
            {
                state = false;
                MessageBox.Show("请检查输入项");
            }
        }
Exemple #3
0
 void UDP_Receive(IAsyncResult ar)
 {
     try
     {
         IPEndPoint Remote_Point = new IPEndPoint(0, 0);
         var        Data         = UDP_Client.EndReceive(ar, ref Remote_Point);
         if (Local_Point == null)
         {
             Local_Point = Remote_Point;
         }
         if (Remote_Point.Equals(Local_Point))
         {
             UDP_Send(DataHandle.En_Bytes(Data), Proxy_Point);
         }
         else if (Remote_Point.Equals(Proxy_Point))
         {
             UDP_Send(DataHandle.De_Bytes(Data), Local_Point);
         }
         UDP_Client.BeginReceive(UDP_Receive, null);
     }
     catch (Exception) {
     }
 }