protected override void Start(CancellationToken token)
        {
            UdpClient = new UdpClient(OriginalEndPoint);
            EndPoint  = (IPEndPoint)UdpClient.Client.LocalEndPoint;

            token.Register(() => UdpClient.SafeDispose());

            UdpClient.JoinMulticastGroup(MulticastIpAddress);
            ReceiveAsync(UdpClient, token);
        }
Esempio n. 2
0
        protected override void Start(CancellationToken token)
        {
            UdpClient client = Client = new UdpClient(OriginalEndPoint);

            EndPoint = (IPEndPoint)client.Client.LocalEndPoint;
            token.Register(() => {
                client.SafeDispose();
                Client = null;
            });

            ReceiveAsync(client, token);
        }
Esempio n. 3
0
        protected override void Start(CancellationToken token)
        {
            UdpClient = new UdpClient(OriginalEndPoint);
            EndPoint  = (IPEndPoint)UdpClient.Client.LocalEndPoint;

            token.Register(() => UdpClient.SafeDispose());

            // enumerating all active IP interfaces and joining their multicast group, so we can reliably listen
            // on systems with multiple NIC
            var nics = NetworkInterface.GetAllNetworkInterfaces();

            foreach (var nic in nics)
            {
                if ((!nic.Supports(NetworkInterfaceComponent.IPv4)) || (nic.OperationalStatus != OperationalStatus.Up))
                {
                    continue;
                }

                IPAddress ip = null;
                foreach (var uni in nic.GetIPProperties().UnicastAddresses)
                {
                    if (uni.Address.AddressFamily != AddressFamily.InterNetwork)
                    {
                        continue;
                    }

                    ip = uni.Address;
                }

                if (ip == null)
                {
                    continue;
                }

                UdpClient.JoinMulticastGroup(MulticastAddressV4.Address, ip);
            }

            ReceiveAsync(UdpClient, token);
        }