/// <summary>
        /// 解析字节数据
        /// </summary>
        /// <param name="connection">要解析数据的连接</param>
        private void ProcessData(Connection connection)
        {
            if (connection.length < sizeof(Int32))
            {
                Debug.Log("获取不到信息大小重新接包解析:" + connection.length.ToString());
                return;
            }
            Array.Copy(connection.readBuff, connection.lenBytes, sizeof(Int32));
            connection.msgLength = BitConverter.ToInt32(connection.lenBytes, 0);

            if (connection.length < connection.msgLength + sizeof(Int32))
            {
                Debug.Log("信息大小不匹配重新接包解析:" + connection.length + ":" + (connection.msgLength + 4).ToString());
                return;
            }
            //ServerDebug.Log("接收信息大小:" + connection.msgLength.ToString(), 1);
            // string str = Encoding.UTF8.GetString(connection.readBuff, sizeof(Int32), connection.length);

            ProtocolBase message = new ByteProtocol();

            // Debug.Log(DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond+"接收消息大小:" + connection.msgLength);
            message.InitMessage(connection.ReceiveBytes);
            MessageList.Enqueue(message);
            //    Debug.Log("ProcessDataOver");
            //Send(connection, str);
            int count = connection.length - connection.msgLength - sizeof(Int32);

            Array.Copy(connection.readBuff, sizeof(Int32) + connection.msgLength, connection.readBuff, 0, count);
            connection.length = count;
            if (connection.length > 0)
            {
                ProcessData(connection);
            }
        }
Example #2
0
        /// <summary>
        /// 发送本地客户端帧信息
        /// </summary>
        protected void SendClientFrame(object sender, ElapsedEventArgs e)
        {
            if (client.ServerCon.clientId < 0)
            {
                return;
            }
            ProtocolBase protocol = new ByteProtocol();

            protocol.push((byte)MessageType.Frame);
            protocol.push((byte)client.ServerCon.clientId);

            foreach (var bt in sendKey.GetBytes())
            {
                protocol.push(bt);
            }



            protocol.push((byte)joySticks.Count);
            // Debug.LogError("len"+joySticks.Count);
            foreach (var joy in joySticks)
            {
                //  Debug.LogError("key"+joy.Key);
                protocol.push((byte)joy.Key);
                protocol.push(joy.Value.direction);
            }

            client.Send(protocol.GetByteStream());
        }
Example #3
0
        public static void Deserialize(Action <ByteProtocol> deserialize, byte[] byteData)
        {
            var pro = new ByteProtocol();

            pro.InitMessage(byteData);
            deserialize(pro);
        }
Example #4
0
        public static Byte[] Serialize(Action <ByteProtocol> serialize)
        {
            var pro = new ByteProtocol();

            serialize(pro);
            return(pro.GetByteStream());
        }
        public void Deserialize(ByteProtocol protocol)
        {
            var len = protocol.getInt32();

            Debug.LogError("len " + len);
            if (assets == null)
            {
                assets = new List <T>();
            }
            for (int i = 0; i < len; i++)
            {
                if (i >= assets.Count)
                {
                    var assetsData = new T();
                    assetsData.data = new DataT();
                    assetsData.data.Deserialize(protocol);
                    assets.Add(assetsData);
                }
                else
                {
                    assets[i].data.Deserialize(protocol);
                }
            }
            for (int i = 0; i < len; i++)
            {
                assets[i].Deserialize(protocol);
            }
        }
 public void Serialize(ByteProtocol protocol)
 {
     protocol.push(dic.Count);
     foreach (var kv in dic)
     {
         protocol.push(kv.key);
         protocol.push(kv.value);
     }
 }
        private void SendPingMsg()
        {
            m_dtLastPingTime = DateTime.Now;
            ProtocolBase protocol = new ByteProtocol();

            protocol.push((byte)MessageType.Ping);
            protocol.push((byte)ServerCon.clientId);
            this.Send(protocol.GetByteStream());
        }
        public void Deserialize(ByteProtocol protocol)
        {
            dic.Clear();
            var len = protocol.getInt32();

            for (int i = 0; i < len; i++)
            {
                dic.Add(new KeyFixed(protocol.getString(), protocol.getRatio()));
            }
        }
 public void Serialize(ByteProtocol protocol)
 {
     protocol.push(assets.Count);
     foreach (var assetsData in assets)
     {
         assetsData.data.Serialize(protocol);
     }
     foreach (var assetsData in assets)
     {
         assetsData.Serialize(protocol);
     }
 }
        public virtual void Deserialize(ByteProtocol protocol)
        {
            table.Clear();
            var len = protocol.getInt32();

            for (int i = 0; i < len; i++)
            {
                var data = new T();
                data.Deserialize(protocol);

                table.Add(data.Id, data);
            }
            Debug.Log("AI初始化完毕 AI数" + table.Count);
        }
 public virtual void Serialize(ByteProtocol protocol)
 {
     throw new NotImplementedException();
 }
 public virtual void Deserialize(ByteProtocol protocol)
 {
     throw new System.NotImplementedException();
 }