示例#1
0
 // Update is called once per frame
 void Update()
 {
     while (NetWorkScript.Instance.messageList.Count > 0)
     {
         SocketModel model = NetWorkScript.Instance.messageList[0];
         NetWorkScript.Instance.messageList.RemoveAt(0);
         StartCoroutine("MessageReceive", model);
     }
 }
示例#2
0
 void MessageReceive(SocketModel model)
 {
     switch (model.type)
     {
         //case Protocol.TYPE_USER:
         //    user.MessageReceive(model);
         //    break;
         //case Protocol.TYPE_LOGIN:
         //    login.MessageReceive(model);
         //    break;
     }
 }
示例#3
0
        public static SocketModel mDecode(byte[] value)
        {
            ByteArray   ba = new ByteArray(value);
            SocketModel sm = new SocketModel();
            int         type;
            int         area;
            int         command;

            ba.read(out type);
            ba.read(out area);
            ba.read(out command);
            sm.type    = type;
            sm.area    = area;
            sm.command = command;
            if (ba.Readnable)
            {
                byte[] message;
                ba.read(out message, ba.Length - ba.Position);
                sm.message = SerializeUtil.decoder(message);
            }
            ba.Close();
            return(sm);
        }
示例#4
0
        private void onData()
        {
            //消息体长度为一个4字节数值 长度不足的时候 说明消息未接收完成 或者是废弃消息
            if (cache.Count < 4)
            {
                isRead = false;
                return;
            }

            byte[] result = ldecode(ref cache);

            if (result == null)
            {
                isRead = false;
                return;
            }
            //转换为传输模型用于使用
            SocketModel model = mDecode(result);

            //将消息存储进消息列表 等待Unity来读取
            messageList.Add(model);
            onData();
        }