Пример #1
0
 private void listen() {
     IPEndPoint e = new IPEndPoint(IPAddress.Any, PORT);
     udpListener = new UdpClient(e);
     udpState = new UDPState();
     udpState.Endpoint = e;
     udpState.UdpClient = udpListener;
     udpListener.JoinMulticastGroup(IPAddress.Parse(MULTICAST_ADDR));
     udpListener.Ttl = 1;
     udpListener.BeginReceive(new AsyncCallback(ReceiveCallback), udpState);
 }
Пример #2
0
        public Client() {
            Client.Instance = this;
            
            string curIP;
            int indexip = 0;
            do {
                curIP = Dns.GetHostEntry(Dns.GetHostName()).AddressList[indexip].ToString();
                ClientIP = IPAddress.Parse(curIP).GetAddressBytes()[3];
                indexip++;
            } while (ClientIP == 0 || ClientIP == 76 || IPAddress.Parse(curIP).GetAddressBytes()[2] == 42 || IPAddress.Parse(curIP).GetAddressBytes()[2] == 43);
            // NOTE : 4th octect is 0 or 76 = probable local loop IPs ; 3rd octect is 42 or 43 = default Android tethering

            Handle = Environment.MachineName;
            UserSelectedColor = 0;
            udpClient = new UdpClient();
            udpClient.JoinMulticastGroup(IPAddress.Parse(MULTICAST_ADDR));
            udpClient.MulticastLoopback = true;
            udpState = new UDPState();
            listen();
        }