Exemplo n.º 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
    }
Exemplo n.º 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);
    }
Exemplo n.º 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));
        }
Exemplo n.º 4
0
        public void Start()
        {//==========
            msgProtobuf = new MsgProtobuf();
            //=============
            var ip  = IPAddress.Parse("127.0.0.1");
            var iep = new IPEndPoint(ip, 6091);

            _tcp = new TcpConnection(new PackageExample());
            _tcp.OnConnecting += OnConnecting;
            _tcp.OnConnected  += OnConnected;
            _tcp.OnReceive    += OnReceive;

            _tcp.Connect(iep); //start connect
        }
Exemplo n.º 5
0
 void OnMsg_Protobuf(IByteArray byteArray)
 {
     var        msg       = new MsgProtobuf(byteArray);
     GameObject testClass = msg.Read <GameObject>();//your class's type
     var        testName  = testClass.name;
 }
Exemplo n.º 6
0
        public void Unpack(IByteArray bytes)
        {
            MsgProtobuf msg = new MsgProtobuf(bytes);

            msg.Read <int>();
        }
Exemplo n.º 7
0
 void OnMsg(IByteArray iByteArray)
 {
     MsgProtobuf msgBytes = new MsgProtobuf(iByteArray);
     Role        role     = msgBytes.Read <Role>();
 }