示例#1
0
        public override ProtocolBase Decode(byte[] readbuff, int start, int length)
        {
            CustomProtocol protocol = new CustomProtocol();

            protocol.bytes = new byte[length];
            Array.Copy(readbuff, start, protocol.bytes, 0, length);
            return(protocol);
        }
示例#2
0
        private static void HeartTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            double currTime = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
            bool   flag     = currTime - Connection.lastTime > 150.0;

            if (flag)
            {
                Connection.isConnected = false;
                bool flag2 = Connection.login != null;
                if (flag2)
                {
                    Connection.dislogin();
                }
            }
            else
            {
                CustomProtocol protoHeart = new CustomProtocol();
                protoHeart.AddString("EZ1");
                Connection.Send(protoHeart);
                Connection.heartTimer.Start();
            }
        }
示例#3
0
 public static void Start()
 {
     Connection.protocol = new CustomProtocol();
     Connection.socket   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     try
     {
         Connection.socket.Connect("106.14.15.66", 1234);
         Connection.isConnected = true;
         CustomProtocol protoHeart = new CustomProtocol();
         protoHeart.AddString("EZ1");
         Connection.Send(protoHeart);
         Connection.lastTime             = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds;
         Connection.heartTimer.AutoReset = false;
         Connection.heartTimer.Elapsed  += new ElapsedEventHandler(Connection.HeartTimer_Elapsed);
         Connection.heartTimer.Start();
     }
     catch
     {
         MessageBox.Show(MultiLanguage.Hint6, MultiLanguage.Warn);
         Connection.isConnected = false;
         return;
     }
     Connection.socket.BeginReceive(Connection.readBuff, 0, 8192, SocketFlags.None, new AsyncCallback(Connection.ReceiveCallback), null);
 }