예제 #1
0
 public void OnDisconnect()
 {
     if (!_isConnected)
     {
         return;
     }
     _isConnected = false;
     ConnSocket.Close();
     if (null != OnDisconnectListener)
     {
         OnDisconnectListener(this);
     }
 }
예제 #2
0
        /// <summary>
        /// 清理关闭soket
        /// Close all work and release all resource.
        /// </summary>
        private void SocketClose()
        {
            try
            {
                if (ConnSocket != null)
                {
                    lock (_lockSocket)
                    {
                        ConnSocket.Close();
                    }
                }

                // 删除两个IDispose数据,避免connect释放不了的问题
                if (m_connEventArg != null)
                {
                    m_connEventArg.Dispose();
                    m_connEventArg = null;
                }

                if (m_receiveEventArg != null)
                {
                    m_receiveEventArg.Dispose();
                    m_receiveEventArg = null;
                }

                // 清理timer
                if (m_disconnectTimer != null)
                {
                    m_disconnectTimer.Dispose();
                    m_disconnectTimer = null;
                }
            }
            catch (Exception ex)
            {
                String msg = String.Format("{0}:{1}", ex.GetType().ToString(), ex.Message);
                Debug.WriteLine(msg);
                //throw ex;
            }
        }