// Protocol: Logout
        // Rec Args: int[logout reason]
        // Return: int[0-logout normally]
        public void MsgLogout(Conn conn, ProtocolBytes protoBase)
        {
            ProtocolBytes protocolRet = new ProtocolBytes();

            protocolRet.AddString("Logout");
            protocolRet.AddInt32(0);
            Console.WriteLine("[HandleConnMsg.MsgLogout] Receive Logout protocol.");

            conn.Send(protocolRet);

            if (conn.player != null)
            {
                conn.player.Logout();
            }
            else
            {
                conn.Close();
            }
        }
Пример #2
0
        /// <summary>
        /// Check all the conn and disconnect it which appear heartbeat.
        /// </summary>
        void HeartBeat()
        {
            long nowTime = Sys.GetTimeStamp();

            for (int i = 0; i < conns.Length; i++)
            {
                Conn conn = conns [i];
                if (conn == null || conn.isUse == false)
                {
                    continue;
                }

                if (nowTime - conn.lastTickTime > heartBeatTime)
                {
                    Console.WriteLine("[ServNet.HeartBeat] HeartBeat case disconnect with " + conn.GetAddress());
                    lock (conn) {
                        conn.Close();
                    }
                }
            }
        }
Пример #3
0
        //心跳协议
        public void HeartBeat()
        {
            long timeNow = Sys.GetTimeStamp();

            for (int i = 0; i < conns.Length; i++)
            {
                Conn conn = conns[i];
                if (conn == null)
                {
                    continue;
                }
                if (!conn.isUse)
                {
                    continue;
                }
                if (conn.lastTickTime < timeNow - heartBeatTime)
                {
                    Console.WriteLine("[心跳机制触发,断开连接]" + conn.GetAddr());
                    lock (conn) conn.Close();
                }
            }
        }
        //心跳
        public void HeartBeat()
        {
            long timeNow = Sys.GetTimeStamp();

            for (int i = 0; i < conns.Length; i++)
            {
                Conn conn = conns[i];
                if (conn == null)
                {
                    continue;
                }
                if (!conn.isUse)
                {
                    continue;
                }

                if (conn.lastTickTime < timeNow - heartBeatTime)
                {
                    lock (conn)
                        conn.Close();
                }
            }
        }
Пример #5
0
        //心跳
        public void HeartBeat()
        {
            //Console.WriteLine("[主定时器执行]");
            long timeNow = Sys.GetTimeStamp();

            for (int i = 0; i < conns.Length; i++)
            {
                Conn conn = conns[i];
                if (conn == null)
                {
                    return;
                }
                if (!conn.isUse)
                {
                    return;
                }
                if (conn.lastTickTime < timeNow - heartBeatTime)
                {
                    Console.WriteLine("[心跳引起断开连接]" + conn.GetAdress());
                    lock (conn)
                        conn.Close();
                }
            }
        }
Пример #6
0
        void ReceiveCb(IAsyncResult ar)
        {
            Conn conn = (Conn)ar.AsyncState;

            try {
                int count = conn.socket.EndReceive(ar);
                if (count > 0)
                {
                    conn.buffCount += count;
                    ProcessData(conn);
                }

                conn.socket.BeginReceive(
                    conn.readBuff,
                    conn.buffCount,
                    conn.BufferRemain(),
                    SocketFlags.None,
                    ReceiveCb,
                    conn);
            } catch (Exception ex) {
                Console.WriteLine("[ServNet.ReceiveCb] Receive byte fail." + ex.Message);
                conn.Close();
            }
        }