/// <summary> /// Set address to listen on. /// </summary> /// <param name="addr">a string denoting the address to set this to</param> public virtual void SetAddress(string addr) { m_address.Resolve(addr, m_options.IPv4Only); Assumes.NotNull(m_address.Address); try { m_handle = AsyncSocket.Create(m_address.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); Assumes.NotNull(m_handle); if (!m_options.IPv4Only && m_address.Address.AddressFamily == AddressFamily.InterNetworkV6) { try { // This is not supported on old windows operating systems and might throw exception m_handle.SetSocketOption(SocketOptionLevel.IPv6, IPv6Only, 0); } catch { } } #if NETSTANDARD2_0 || NETSTANDARD2_1 // This command is failing on linux if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { m_handle.ExclusiveAddressUse = false; } #else m_handle.ExclusiveAddressUse = false; #endif m_handle.Bind(m_address.Address); m_handle.Listen(m_options.Backlog); // Copy the port number after binding in case we requested a system-allocated port number (TCP port zero) m_address.Address.Port = m_handle.LocalEndPoint.Port; m_endpoint = m_address.ToString(); m_socket.EventListening(m_endpoint, m_handle); m_port = m_handle.LocalEndPoint.Port; } catch (SocketException ex) { Close(); throw NetMQException.Create(ex); } }
/// <summary> /// Set address to listen on. /// </summary> /// <param name="addr">a string denoting the address to set this to</param> public virtual void SetAddress([NotNull] string addr) { m_address.Resolve(addr, m_options.IPv4Only); try { m_handle = AsyncSocket.Create(m_address.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); Debug.Assert(m_handle != null); if (!m_options.IPv4Only && m_address.Address.AddressFamily == AddressFamily.InterNetworkV6) { try { // This is not supported on old windows operation system and might throw exception m_handle.SetSocketOption(SocketOptionLevel.IPv6, IPv6Only, 0); } catch { } } m_handle.ExclusiveAddressUse = false; m_handle.Bind(m_address.Address); m_handle.Listen(m_options.Backlog); // Copy the port number after binding in case we requested a system-allocated port number (TCP port zero) m_address.Address.Port = m_handle.LocalEndPoint.Port; m_endpoint = m_address.ToString(); m_socket.EventListening(m_endpoint, m_handle); m_port = m_handle.LocalEndPoint.Port; } catch (SocketException ex) { Close(); throw NetMQException.Create(ex); } }