示例#1
0
        /// <summary>
        /// Disconnect the client socket
        /// </summary>
        public void Disconnect()
        {
            lock (m_generalLock)
            {
                if (!IsConnectionAlive())
                {
                    return;
                }
                m_client.Close();
                m_isConnected = false;
            }
            m_server.DetachClient(this);

            lock (m_sendQueueLock)
            {
                m_sendQueue.Clear();
            }
            if (m_callBackObj != null)
            {
                Thread t = new Thread(delegate()
                {
                    m_callBackObj.OnDisconnect(this);
                });
                t.Start();
            }
        }
        /// <summary>
        /// Disconnect the client socket
        /// </summary>
        public void Disconnect()
        {
            lock (m_generalLock)
            {
                if (!IsConnectionAlive)
                {
                    return;
                }
                try
                {
                    m_client.Client.Shutdown(SocketShutdown.Both);
                    //m_client.Client.Disconnect(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + " >" + ex.StackTrace);
                }
                m_client.Close();
                IsConnectionAlive = false;
            }
            m_server.DetachClient(this);

            List <IRoom> roomList = Rooms;

            foreach (IRoom room in roomList)
            {
                ((IocpTcpServer)m_server).Leave(this, room.RoomName);
            }
            lock (m_roomLock)
            {
                m_roomMap.Clear();
            }

            lock (m_sendQueueLock)
            {
                m_sendQueue.Clear();
            }
            Task t = new Task(delegate()
            {
                OnDisconnect(this);
            });

            t.Start();
        }