示例#1
0
        public Listener(IPEndPoint ipep)
        {
            m_Accepted         = new Queue <Socket>();
            m_AcceptedSyncRoot = ((ICollection)m_Accepted).SyncRoot;

            m_Listener = Bind(ipep);

            if (m_Listener == null)
            {
                return;
            }

            DisplayListener();
            _PingListener = new PingListener(ipep);

            m_OnAccept = OnAccept;
            try
            {
                IAsyncResult res = m_Listener.BeginAccept(m_OnAccept, m_Listener);
            }
            catch (SocketException ex)
            {
                NetState.TraceException(ex);
            }
            catch (ObjectDisposedException)
            { }
        }
示例#2
0
文件: Listener.cs 项目: pallop/Servuo
        public Listener(IPEndPoint ipep)
        {
            m_Accepted         = new Queue <Socket>();
            m_AcceptedSyncRoot = ((ICollection)m_Accepted).SyncRoot;

            m_Listener = Bind(ipep);

            if (m_Listener == null)
            {
                return;
            }

            DisplayListener();
            _PingListener = new PingListener(ipep);

#if NewAsyncSockets
            m_EventArgs            = new SocketAsyncEventArgs();
            m_EventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(Accept_Completion);
            Accept_Start();
#else
            m_OnAccept = OnAccept;
            try
            {
                IAsyncResult res = m_Listener.BeginAccept(m_OnAccept, m_Listener);
            }
            catch (SocketException ex)
            {
                NetState.TraceException(ex);
            }
            catch (ObjectDisposedException)
            { }
#endif
        }
示例#3
0
        public void Dispose()
        {
            Socket socket = Interlocked.Exchange(ref m_Listener, null);

            if (socket != null)
            {
                socket.Close();
            }

            if (_PingListener == null)
            {
                return;
            }

            _PingListener.Dispose();
            _PingListener = null;
        }