public DeviceDiscoveryService(DeviceDiscoverySettings settings)
        {
            _broadcastIp = IPAddress.Parse(settings.BroadcastIpAddress);
            _endpoint = new IPEndPoint(_broadcastIp, settings.BroadcastPort);

            _multicastSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _multicastSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
                new MulticastOption(_broadcastIp));
            _multicastSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 2);
            _multicastSocket.Connect(_endpoint);

            _listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            var receiveEndpoint = new IPEndPoint(IPAddress.Any, settings.BroadcastPort);
            _listeningSocket.Bind(receiveEndpoint);
            _listeningSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
                new MulticastOption(_broadcastIp, IPAddress.Any));

            _settings = settings;
        }
Exemplo n.º 2
0
 public DeviceDiscoveryService(DeviceDiscoverySettings settings)
 {
 }