Пример #1
0
        public void ReceiveHandle()
        {
            if (cacheList.Count < 4)
            {
                receive = false;
                return;
            }
            byte[] data = EncodingUtil.LengthDecode(ref cacheList);
            if (data == null)
            {
                receive = false;
                return;
            }
            SocketModel model = EncodingUtil.SocketModelDncode(data);

            iCenterHandler.Receive(model);
            ReceiveHandle();
        }
Пример #2
0
        public static SocketModel SocketModelDncode(byte[] bytes)
        {
            SocketModel model = new SocketModel();

            using (MemoryStream stream = new MemoryStream(bytes))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    model.type    = reader.ReadByte();
                    model.area    = reader.ReadInt32();
                    model.command = reader.ReadInt32();
                    if (stream.Length > stream.Position)
                    {
                        model.message = DeserializationDecode(reader.ReadBytes((int)(stream.Length - stream.Position)));
                    }
                }
            }
            return(model);
        }
Пример #3
0
 public static byte[] SocketModelEncode(SocketModel model)
 {
     byte[] bytes;
     using (MemoryStream stream = new MemoryStream())
     {
         using (BinaryWriter writer = new BinaryWriter(stream))
         {
             writer.Write(model.type);
             writer.Write(model.area);
             writer.Write(model.command);
             if (model.message != null)
             {
                 writer.Write(SerializationEncode(model.message));
             }
             bytes = stream.ToArray();
         }
     }
     return(bytes);
 }