public static void SendMsg(this SyncSession session, string key, Dictionary <string, object> data)
        {
            ByteArray ba = new ByteArray();

            List <byte> message = GetSendByte(key, data);

            int len    = 3 + message.Count;
            int method = GetMethodIndex(key);

            ba.WriteShort(len);
            ba.WriteByte((byte)(method / 100));
            ba.WriteShort(method);

            if (message != null)
            {
                ba.bytes.AddRange(message);
            }
            else
            {
                ba.WriteInt(0);
            }

            byte[] buffer = ba.Buffer;
            session.Send(buffer, 0, buffer.Length);
        }
        public static void Send(this SyncSession session, ProtocolRequestBase msg)
        {
            ByteArray ba = new ByteArray();

            ba.bytes.AddRange(GetSendByte(msg.Key, msg.m_data));

            byte[] buffer = ba.Buffer;

            session.Send(buffer, 0, buffer.Length);
        }
Beispiel #3
0
        public static void SendMsg(this SyncSession session, string key, Dictionary <string, object> data)
        {
            if (session == null)
            {
                //Debug.LogError("Session 已经断开连接!");
                return;
            }

            ByteArray ba = new ByteArray();

            List <byte> message = GetSendByte(key, data);

            int len    = 3 + message.Count;
            int method = GetMethodIndex(key);

            ba.WriteShort(len);
            ba.WriteByte((byte)(method / 100));
            ba.WriteShort(method);

            if (message != null)
            {
                ba.bytes.AddRange(message);
            }
            else
            {
                ba.WriteInt(0);
            }

            byte[] buffer = ba.Buffer;

            try
            {
                int time = ServiceTime.GetServiceTime();
                session.Send(buffer, 0, buffer.Length);

                if (ServiceTime.GetServiceTime() - time > 10)
                {
                    Debug.Log("发送时间 " + (ServiceTime.GetServiceTime() - time));
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Send Messge Exception " + e.ToString());
            }
        }