示例#1
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="ipAddress">The IP address of the local network adapter to bind sockets to.
        /// Null or empty string will use <see cref="IPAddress.Any"/>.</param>
        public SocketFactory(string ipAddress)
        {
            if (String.IsNullOrEmpty(ipAddress))
            {
                _LocalIP = IPAddress.Any;
            }
            else
            {
                _LocalIP = IPAddress.Parse(ipAddress);
            }

            _DeviceNetworkType = GetDeviceNetworkType(_LocalIP.AddressFamily);
        }
示例#2
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="localIP">A string containing the IP address of the local network adapter to bind sockets to. Null or empty string will use IPAddress.Any.</param>
 public SocketFactory(string localIP)
 {
     _DeviceNetworkType = DeviceNetworkType.IPv4;
     _LocalIP           = localIP;
     if (!String.IsNullOrEmpty(localIP))
     {
         var hostName = new Windows.Networking.HostName(localIP);
         if (hostName.Type == Windows.Networking.HostNameType.Ipv6)
         {
             _DeviceNetworkType = DeviceNetworkType.IPv6;
         }
     }
 }
示例#3
0
        /// <summary>
        /// Get multicast ip address for ipv4 or ipv6 network by <see cref="DeviceNetworkType"/>
        /// </summary>
        /// <param name="deviceNetworkType"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public static string GetMulticastIPAddress(this DeviceNetworkType deviceNetworkType)
        {
            string multicastIpAddress;

            switch (deviceNetworkType)
            {
            case DeviceNetworkType.IPv4:
                multicastIpAddress = SsdpConstants.MulticastLocalAdminAddress;
                break;

            case DeviceNetworkType.IPv6:
                multicastIpAddress = SsdpConstants.MulticastLinkLocalAddressV6;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(deviceNetworkType));
            }

            return(multicastIpAddress);
        }