コード例 #1
0
        //  Set address to listen on. return the used port
        public virtual void SetAddress(String addr)
        {
            m_address.Resolve(addr, m_options.IPv4Only);

            m_endpoint = m_address.ToString();
            try
            {
                m_handle =
                    new Socket(m_address.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                //handle.Blocking = false;

                m_handle.ExclusiveAddressUse = false;
                m_handle.Bind(m_address.Address);
                m_handle.Listen(m_options.Backlog);
            }
            catch (SocketException ex)
            {
                Close();
                throw NetMQException.Create(ex);
            }

            m_socket.EventListening(m_endpoint, m_handle);

            m_port = ((IPEndPoint)m_handle.LocalEndPoint).Port;
        }
コード例 #2
0
ファイル: TcpListener.cs プロジェクト: ryanjshaw/netmq
        //  Set address to listen on. return the used port
        public virtual void SetAddress(String addr)
        {
            m_address.Resolve(addr, m_options.IPv4Only);

            m_endpoint = m_address.ToString();
            try
            {
                m_handle =
                    new Socket(m_address.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                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, SocketOptionName.IPv6Only, 0);
                    }
                    catch
                    {
                    }
                }

                //handle.Blocking = false;

                m_handle.ExclusiveAddressUse = false;
                m_handle.Bind(m_address.Address);
                m_handle.Listen(m_options.Backlog);
            }
            catch (SocketException ex)
            {
                Close();
                throw NetMQException.Create(ex);
            }

            m_socket.EventListening(m_endpoint, m_handle);

            m_port = ((IPEndPoint)m_handle.LocalEndPoint).Port;
        }