コード例 #1
0
ファイル: TestClient.cs プロジェクト: IS1103/uwnp-client
        public async void SendAPI()
        {
            //請求/響應
            TestRq           testRq = new TestRq();
            Message <TestRp> a      = await client.RequestAsync <TestRq, TestRp>("TestController.testA", testRq);

            if (a.err > 0)
            {
                Debug.LogWarning("err:" + a.err);
                Debug.LogWarning("err msg:" + a.errMsg);
            }
            else
            {
                Debug.Log("a:" + a.info.packageType);
            }
        }
コード例 #2
0
ファイル: TestClient.cs プロジェクト: IS1103/uwnp-client
        private async UniTaskVoid CreateConeccetion()
        {
            Debug.Log("開始連線..." + host);

            int  count      = 3;
            bool isConeccet = false;

            while (count-- > 0 && !isConeccet)
            {
                Debug.Log(host);
                isConeccet = await client.ConnectAsync("jon");
            }

            if (isConeccet)
            {
                img.gameObject.SetActive(true);

                // On
                client.On("testOn", (Package pack) => {
                    TestPush info = MessageProtocol.DecodeInfo <TestPush>(pack.buff);
                    Debug.Log(JsonUtility.ToJson(info));
                    //img.gameObject.SetActive(false);
                });

                //請求/響應
                TestRq           testRq = new TestRq();
                Message <TestRp> a      = await client.RequestAsync <TestRq, TestRp>("TestController.testA", testRq);

                if (a.err > 0)
                {
                    Debug.LogWarning("err:" + a.err);
                    Debug.LogWarning("err msg:" + a.errMsg);
                }
                else
                {
                    Debug.Log("a:" + a.info.packageType);
                }

                //請求/響應
                Message <TestRp2> a3 = await client.RequestAsync <TestRq, TestRp2>("TestController.testC", null, "custom1");

                if (a3.err > 0)
                {
                    Debug.LogWarning("err:" + a3.err);
                    Debug.LogWarning("err msg:" + a3.errMsg);
                }
                else
                {
                    Debug.Log("a:" + a3.info.info);
                }

                //通知
                //TestNotify testRq2 = new TestNotify() { name="小叮噹" };
                //client.Notify("TestController.testB", testRq2);
                //*/
            }
            else
            {
                Debug.Log("多次嘗試連線但依然未連線");
            }
        }