Пример #1
0
        private ServerCon StartTheRepeat(string IP, int Port)
        {
            Console.WriteLine("Подключение к серверу, попытка " + count_try);

            ServerCon servcon = SendUDP._ConnectionUDP(IP, Port);

            return(servcon);
        }
Пример #2
0
        public static ServerCon _ConnectionUDP(string IP, int port)
        {
            IPAddress  broadcast = IPAddress.Parse(IP);
            IPEndPoint ep        = new IPEndPoint(broadcast, port);
            UdpClient  Connec    = new UdpClient(port);

            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            s.MulticastLoopback = true;
            s.ReceiveTimeout    = 5000;
            Send_Messg(Connec, "ping_1", ep);
            byte[] reciv = Whait_Messg(Connec, ep);
            //string you_ip = BaseTool.Convertbtst(reciv);
            ServerCon _new_ser = new ServerCon(Connec, ep);

            return(_new_ser);
        }
Пример #3
0
 public Connection(string IP, int Port)
 {
     while (servcon == null & count_try < 5)
     {
         try
         {
             count_try++;
             servcon   = StartTheRepeat(IP, Port);
             isConnect = true;
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
             isConnect = false;
         }
     }
 }