Пример #1
0
    //public object SerializeData(int dest, int cmd,object instance)
    //{
    //    Debug.Log("SerializeData");

    //    MemoryStream memStream = new MemoryStream();
    //    ProtoBuf.Serializer.Serialize(memStream, instance);

    //    byte[] body = memStream.ToArray();
    //    CMsg _nnn = new CMsg();
    //    _nnn.dest = dest;
    //    _nnn.cmd = cmd;
    //    if (body != null && body.Length > 0)
    //    {
    //        _nnn.body = body;
    //    }

    //    //放在消息队列里面发
    //    SendPBMsg smsg = new SendPBMsg();
    //    smsg.dest = dest;
    //    smsg.cmd = cmd;
    //    smsg.sendBody = PBParseManage.getSerialize<CMsg>(_nnn);

    //    NetWorkManage.getInstance().PushSendDataQueue(smsg);

    //    return null;

    //}

    public void SerializeData(SendDataStruct data)
    {
        MemoryStream memStream = new MemoryStream();

        ProtoBuf.Serializer.Serialize(memStream, data.instance);

        byte[] body = memStream.ToArray();
        CMsg   _nnn = new CMsg();

        _nnn.dest = data.dest;
        _nnn.cmd  = data.cmd;
        if (body != null && body.Length > 0)
        {
            _nnn.body = body;
        }

        //放在消息队列里面发
        SendPBMsg smsg = new SendPBMsg();

        smsg.dest     = data.dest;
        smsg.cmd      = data.cmd;
        smsg.sendBody = PBParseManage.getSerialize <CMsg>(_nnn);

        NetWorkManage.getInstance().PushSendDataQueue(smsg);
    }
Пример #2
0
    //发送协议数据到服务器 只传协议号,没有内容
    public static void SendData(int dest, int cmd)
    {
#if UNITY_EDITOR
        Debug.Log("要发送协议:dest=" + dest + ",cmd=" + cmd);
#endif
        SendPBMsg smsg = new SendPBMsg();
        smsg.dest = dest;
        smsg.cmd  = cmd;
        CMsg _nnn = new CMsg();
        _nnn.dest     = dest;
        _nnn.cmd      = cmd;
        smsg.sendBody = PBParseManage.getSerialize <CMsg>(_nnn);

        sendMemory.Add(smsg);
    }
Пример #3
0
    private void SendBySocket()
    {
        int count = sendMemory.Count;

        if (count == 0)
        {
            return;
        }

        SendPBMsg smsg = sendMemory[0];

        if (_socketCon == null)
        {
            Connect();
        }

        if (_socketCon.Send(smsg.sendBody))
        {
            Debug.Log("发送消息 dest=" + smsg.dest + ",cmd=" + smsg.cmd + " 成功 !");
            sendMemory.RemoveAt(0);
        }
    }
Пример #4
0
    //发送协议数据到服务器
    public static void SendData <T>(int dest, int cmd, T instance) where T : global::ProtoBuf.IExtensible
    {
#if UNITY_EDITOR
        Debug.Log("要发送协议:dest=" + dest + ",cmd=" + cmd);
#endif
        byte[] body = PBParseManage.getSerialize <T>(instance);
        CMsg   _nnn = new CMsg();
        _nnn.dest = dest;
        _nnn.cmd  = cmd;
        if (body != null && body.Length > 0)
        {
            _nnn.body = body;
        }

        //放在消息队列里面发
        SendPBMsg smsg = new SendPBMsg();
        smsg.dest     = dest;
        smsg.cmd      = cmd;
        smsg.sendBody = PBParseManage.getSerialize <CMsg>(_nnn);

        sendMemory.Add(smsg);
    }
Пример #5
0
 public void PushSendDataQueue(SendPBMsg smsg)
 {
     sendMemory.Add(smsg);
 }