コード例 #1
0
    // Use this for initialization
    void Start()
    {
        //registe bytes msg
        MsgManager.Instance.RegisterMsg(110, OnByteMsg);
        //you can registe many msg here
        //....

        //registe protobuf msg
        MsgManager.Instance.RegisterMsg(typeof(TestProtobufStruct).FullName, OnProtobufMsg);
        //....

        //connect(prefer host names)
        ClientTcp socket        = new ClientTcp();
        bool      tempIsConnect = socket.Connect("www.google.com", 111);

        Debug.Log("是否连接成功: " + tempIsConnect);

        // send byte msg
        MsgByte tempMsg1 = new MsgByte(110); //110 is proto id

        tempMsg1.Write <int>(100);           //write msg's body
        tempMsg1.Write("hello");             //write msg's body
        tempMsg1.Flush();                    //send

        //send protobuf msg
        TestProtobufStruct testProtobufStruct = new TestProtobufStruct();

        testProtobufStruct.x = 100;
        testProtobufStruct.y = "hello";
        MsgProtobuf tempMsg2 = new MsgProtobuf();

        tempMsg2.Write(testProtobufStruct);
        tempMsg2.Flush();//send
    }
コード例 #2
0
    void Msg_Protobuf()
    {
        var msg    = new MsgProtobuf();
        var testGo = new GameObject();

        msg.Write(testGo);
        byte[] bytes = msg.ByteArray.Read(msg.ByteArray.Length);
        _tcp.Send(bytes);
    }
コード例 #3
0
        void Send()
        {
            MsgProtobuf msgBytes = new MsgProtobuf();
            Role        role     = new Role();

            role.HP = 10;
            msgBytes.Write(role);
            //tcp.send(msgBytes.ByteArray.Read(msgBytes.ByteArray.Length));
        }