Example #1
0
        public IEnumerator ShouldClientBeAbleToListenToARouteAndReceiveData()
        {
            var    receivedPushResponse = false;
            object response             = null;

            const string expectedResponse = "{\"key1\":10,\"key2\":true}";

            _client.Connect(ServerHost, ServerPort);

            _client.OnRoute("some.push.route",
                            res => {
                receivedPushResponse = true;
                response             = res;
                Assert.AreEqual(_mainThread, Thread.CurrentThread);
            }
                            );

            var    requestFinished  = false;
            object sendPushResponse = null;

            _client.Request(
                "connector.sendpush",
                res => {
                requestFinished  = true;
                sendPushResponse = res;
                Assert.AreEqual(_mainThread, Thread.CurrentThread);
            },
                error => {
                requestFinished  = true;
                sendPushResponse = error;
                Assert.AreEqual(_mainThread, Thread.CurrentThread);
            }
                );

            while (!requestFinished)
            {
                yield return(new WaitForSeconds(0.5f));
            }

            var resp = (JsonObject)SimpleJson.SimpleJson.DeserializeObject((string)sendPushResponse);

            Assert.True(receivedPushResponse);
            Assert.NotNull(response);
            Assert.AreEqual(response, expectedResponse);
            Assert.NotNull(sendPushResponse);
            Assert.AreEqual(resp["Code"], 200);
            Assert.AreEqual(resp["Msg"], "Ok");
        }
Example #2
0
    // Use this for initialization
    private void Start()
    {
        // _client = new PitayaClient("ca.crt");
        _client      = new PitayaClient();
        _connected   = false;
        _requestSent = false;

        _client.NetWorkStateChangedEvent += (ev, error) =>
        {
            if (ev == PitayaNetWorkState.Connected)
            {
                Debug.Log("Successfully connected!");
                _connected = true;
            }
            else if (ev == PitayaNetWorkState.FailToConnect)
            {
                Debug.Log("Failed to connect");
            }
        };

        _client.Connect("a1d127034f31611e8858512b1bea90da-838011280.us-east-1.elb.amazonaws.com", 3251,
                        new Dictionary <string, string>
        {
            { "oi", "mano" }
        });
    }
Example #3
0
        public void Init()
        {
            _client = new PitayaClient();
            PitayaClient.SetLogLevel(PitayaLogLevel.Debug);

            _client.Connect(ServerHost, ServerPort);

            _data          = "{\"Data\":{\"name\":\"test25\"}}";
            _jsonStub      = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(_data);
            _emptyData     = "{\"Data\":{}}";
            _emptyJsonStub = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(_emptyData);

            _isFinished = false;

            Thread.Sleep(300);

            // clearing sessiondata
            _client.Request(
                "connector.setsessiondata",
                _emptyData,
                res => {
                _isFinished = true;
            },
                error => {
                _isFinished = true;
            }
                );
        }
Example #4
0
        public void Init()
        {
            // PitayaBinding.AddPinnedPublicKeyFromCaFile("client-ssl.localhost.crt");
            _mainThread = Thread.CurrentThread;
            PitayaBinding.SkipKeyPinCheck(true);

            _client = new PitayaClient("ca.crt");
            PitayaClient.SetLogLevel(PitayaLogLevel.Debug);

            _client.Connect(ServerHost, ServerPort);

            Thread.Sleep(200);

            _data          = "{\"Data\":{\"name\":\"test25\"}}";
            _jsonStub      = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(_data);
            _emptyData     = "{\"Data\":{}}";
            _emptyJsonStub = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(_emptyData);

            _isFinished = false;

            // clearing sessiondata
            _client.Request(
                "connector.setsessiondata",
                _emptyData,
                res => { _isFinished = true; },
                error => { _isFinished = true; }
                );
        }
        public IEnumerator ShouldConnectCorrectly()
        {
            var called          = false;
            var connectionState = PitayaNetWorkState.Disconnected;

            _client.NetWorkStateChangedEvent += (networkState, error) => {
                called          = true;
                connectionState = networkState;
                Assert.AreEqual(_mainThread, Thread.CurrentThread);
            };

            _client.Connect(ServerHost, ServerPort);

            while (!called)
            {
                yield return(new WaitForSeconds(0.5f));
            }

            Assert.True(called);
            Assert.AreEqual(connectionState, PitayaNetWorkState.Connected);
            Assert.AreEqual(_client.State, PitayaClientState.Connected);
        }
        public void Init()
        {
            _isFinished = false;
            PitayaClient.SetLogLevel(PitayaLogLevel.Debug);

            _client = new PitayaClient();
            _client.Connect(ServerHost, ServerPort);

            _sessionData = new SessionData
            {
                Data = "fake data"
            };
        }
Example #7
0
    // Use this for initialization
    private void Start()
    {
        Debug.Log("Script loaded");
        _client      = new PitayaClient("ca.crt");
        _connected   = false;
        _requestSent = false;

        _client.NetWorkStateChangedEvent += (ev) =>
        {
            if (ev == PitayaNetWorkState.Connected)
            {
                Debug.Log("Successfully connected!");
                _connected = true;
            }
        };

        _client.Connect("a1d127034f31611e8858512b1bea90da-838011280.us-east-1.elb.amazonaws.com", 3252);
    }