コード例 #1
0
ファイル: ServNet.cs プロジェクト: fzzx20080212/Ser
 public void Send(Conn conn, ProtocolBase protocol)
 {
     byte[] bytes    = protocol.Encode();
     byte[] length   = BitConverter.GetBytes(bytes.Length);
     byte[] sendbuff = length.Concat(bytes).ToArray();
     try
     {
         conn.socket.BeginSend(sendbuff, 0, sendbuff.Length, SocketFlags.None, null, null);
     }
     catch (Exception e)
     {
         Console.WriteLine("[发送信息]" + conn.GetAdress() + ":" + e.Message);
     }
 }
コード例 #2
0
ファイル: ServNet.cs プロジェクト: fzzx20080212/Ser
        //心跳
        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();
                }
            }
        }
コード例 #3
0
 public void MsgHeartBeat(Conn conn, ProtocolBase protocolBase)
 {
     conn.lastTickTime = Sys.GetTimeStamp();
     Console.WriteLine("[更新心跳时间]" + conn.GetAdress());
 }