コード例 #1
0
 public void Send <T>(SocketRequestMessage <T> message)
 {
     if (socket.getStatus() == USocket.STATUS_CONNECTED)
     {
         Frame f = socketProtocol.EncodeMessage(message);
         socket.Send(f);
     }
 }
コード例 #2
0
    public virtual void SendMessage(int nPort, CMD_Base_Req req)
    {
        USocket socket = _socketPool.NewSocket(_listener, _protocal);

        socket.Connect(_strIP, nPort, (success) =>
        {
            if (!success)
            {
                return;
            }
            socket.Send(req.Serialize());
        });
    }
コード例 #3
0
        public void Send(MessageID msgId, IMessage msg)
        {
            if (MessageMap.GetMsgType(msgId) != msg.GetType())
            {
                Log.Error("消息号和数据不匹配!");
                return;
            }
            byte[] data  = msg.ToByteArray();
            Frame  frame = new Frame(data.Length + 4);

            frame.PutShort((short)(data.Length + 2)); //写入数据长度
            frame.PutShort((short)msgId);             //写入协议号
            frame.PutBytes(data);                     //写入数据
            socket.Send(frame);
        }
コード例 #4
0
ファイル: SocketTest.cs プロジェクト: zhanghuiyu/cocosocket
    private void Send(object param)
    {
        MemoryStream stream = new MemoryStream();

        ProtoBuf.Serializer.NonGeneric.Serialize(stream, param);
        byte[] bs = stream.ToArray();
        Frame  f  = null;

        if (socket.getProtocal().GetType() == typeof(Varint32HeaderProtocol))
        {
            f = new Varint32Frame(512);
        }
        else
        {
            f = new Frame(512);
        }
        f.PutShort(MessageQueueHandler.GetProtocolCMD(param.GetType()));
        Debug.LogWarning("上行 cmd=" + MessageQueueHandler.GetProtocolCMD(param.GetType()) + ", type=" + param.GetType().ToString() + ", " + Time.fixedTime);
        Statics.SetXor(bs);
        f.PutBytes(bs);
        f.End();
        socket.Send(f);
    }
コード例 #5
0
 public void SendMessage(CMD_Base_Req req)
 {
     _socket.Send(req.Serialize());
 }