public void ShouldSendEventsWithArraybuffersInTheCorrectOrder()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            Flag             = false;
            var buf = System.Text.Encoding.UTF8.GetBytes("abuff1");

            var options = CreateOptions();
            var uri     = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On("abuff2-ack", () =>
            {
                Flag = true;
                ManualResetEvent.Set();
            });


            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
            socket.Emit("abuff1", buf);
            socket.Emit("abuff2", "please arrive second");
            ManualResetEvent.WaitOne(15000);
            Assert.True(Flag);
        }
Ejemplo n.º 2
0
        private static void ConnectToSocket()
        {
            var queryData = new Dictionary <string, string>();

            queryData.Add("token", "12345");
            var dataString = "Test" + DateTime.Now.Ticks.ToString();

            _mainSocket = SOCKETNET35.IO.Socket("http://localhost:3000/",
                                                new SOCKETNET35.IO.Options()
            {
                Query           = queryData,
                RememberUpgrade = true
            });

            _mainSocket.On("hi", (data) =>
            {
                System.Console.WriteLine("Received data: " + data.ToString());
            });

            _mainSocket.On(Socket.IO.NET35.Socket.EVENT_CONNECT, () =>
            {
                System.Console.WriteLine("Connected...");
                _mainSocket.Emit("hi", dataString);
            });
        }
        public void ShouldGetBase64DataAsALastResort()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            var events = new Queue <object>();

            var options = CreateOptions();
            var uri     = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On("takebin", (data) =>
            {
                events.Enqueue(data);
                ManualResetEvent.Set();
            });

            socket.Emit("getbin");

            //socket.Open();
            ManualResetEvent.WaitOne(15000);
            socket.Close();

            var binData   = (byte[])events.Dequeue();
            var exptected = System.Text.Encoding.UTF8.GetBytes("asdfasdf");
            var i         = 0;

            foreach (var b in exptected)
            {
                Assert.Equal(b, binData[i++]);
            }
        }
        public void ShouldEmitDateInObject()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            var events = new Queue <object>();

            var options = CreateOptions();
            var uri     = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On("takeDateObj", (data) =>
            {
                log.Info("takeDate");
                events.Enqueue(data);
                ManualResetEvent.Set();
            });

            socket.Emit("getDateObj");

            //socket.Open();
            ManualResetEvent.WaitOne(15000);
            socket.Close();
            var obj = (JObject)events.Dequeue();

            Assert.IsType <JObject>(obj);
            var date = (obj["date"]).Value <DateTime>();

            Assert.IsType <DateTime>(date);
        }
        public void ShouldWorkWithFalse()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            var events = new Queue <object>();

            var options = CreateOptions();
            var uri     = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On(SOCKETNET35.Socket.EVENT_CONNECT, () =>
            {
                socket.Emit("false");
            });

            socket.On("false", (data) =>
            {
                events.Enqueue(data);
                ManualResetEvent.Set();
            });

            ManualResetEvent.WaitOne(15000);
            socket.Close();
            var obj = events.Dequeue();

            Assert.False((bool)obj);
        }
        public void ShouldReceiveDateWithAckAsAction()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            Message          = "";
            Number           = 0;
            ManualResetEvent = new ManualResetEvent(false);
            var obj = new JObject();

            obj["b"] = true;

            var options = CreateOptions();
            var uri     = CreateUri();

            socket = IO.Socket(uri, options);
            socket.Emit("getAckDate", (date, n) =>
            {
                log.Info("getAckDate data=" + date);
                Message = ((DateTime)date).ToString("O");
                Number  = int.Parse(n.ToString());
                ManualResetEvent.Set();
            }, obj);


            ManualResetEvent.WaitOne(15000);
            Assert.Equal(28, Message.Length);
            Assert.Equal(5, Number);
            socket.Close();
        }
        public void MessageTest()
        {
            //var log = LogManager.GetLogger(GlobalHelper.CallerName());
            //log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            var events       = new Queue <object>();
            var uniqueString = DateTime.Now.Ticks.ToString();
            var options      = CreateOptions();
            var uri          = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On(SOCKETNET35.Socket.EVENT_CONNECT, () =>
            {
                socket.Emit("hi", uniqueString);
            });

            socket.On("hi",
                      (data) =>
            {
                events.Enqueue(data);
                ManualResetEvent.Set();
            });

            ManualResetEvent.WaitOne(15000);
            socket.Close();
            if (events.Count < 1)
            {
                throw new Exception("No work has been done");
            }
            var obj = events.Dequeue();

            Assert.Equal(uniqueString, obj);
        }
        public void CreateSession_ShouldReturnCorrectSessionData()
        {
            // Arrange
            var randomSessionData = DateTime.Now.Ticks.ToString() + Guid.NewGuid();
            var sessionId         = Guid.NewGuid();
            var responseResult    = string.Empty;
            var options           = CreateOptions();
            var uri = CreateUri();

            ManualResetEvent = new ManualResetEvent(false);

            socket = SOCKETNET35.IO.Socket(ServerUrl);

            socket.On(SOCKETNET35.Socket.EVENT_CONNECT, () =>
            {
                socket.Emit("createSession", sessionId, randomSessionData);
            });

            socket.On("createdSession", (responseData) =>
            {
                responseResult = responseData.ToString();
                ManualResetEvent.Set();
            });

            // Act
            ManualResetEvent.WaitOne(15000);
            socket.Close();

            // Assert
            Assert.Equal(randomSessionData, responseResult);
            Assert.NotEqual(string.Empty, responseResult);
            Assert.NotEqual(" ", responseResult);
        }
        public void Json10000000CharsTest()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            var events = new Queue <object>();

            var options = CreateOptions();
            var uri     = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On(SOCKETNET35.Socket.EVENT_CONNECT, () =>
            {
                log.Info("EVENT_CONNECT");
                socket.Emit("json10000000chars");
            });

            socket.On("json10000000chars",
                      (data) =>
            {
                log.Info("EVENT_MESSAGE data=" + data);
                events.Enqueue(data);
                ManualResetEvent.Set();
            });

            //socket.Open();
            ManualResetEvent.WaitOne(15000);
            socket.Close();
            var obj = (JObject)events.Dequeue();
            var str = (string)obj["data"];

            Assert.Equal(10000000, str.Length);
        }
        public void BuffAck()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            Flag             = false;

            var exptected = System.Text.Encoding.UTF8.GetBytes("asdfasdf");

            var options = CreateOptions();
            //options.Transports = ImmutableList.Create<string>(Polling.NAME);
            var uri = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On("buffack", () =>
            {
                Flag = true;
                ManualResetEvent.Set();
            });

            socket.Emit("buffa", exptected);

            ManualResetEvent.WaitOne(15000);
            //Task.Delay(8000).Wait();
            socket.Close();
            //Task.Delay(4000).Wait();
            Assert.True(Flag);
            log.Info("Finish");
        }
        public void ShouldSendBinaryDataAsAnArraybuffer()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            Flag             = false;

            var exptected = System.Text.Encoding.UTF8.GetBytes("asdfasdf");

            var options = CreateOptions();
            var uri     = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On("buffack", () =>
            {
                Flag = true;
                ManualResetEvent.Set();
            });

            socket.Emit("buffa", exptected);

            ManualResetEvent.WaitOne(15000);
            socket.Close();
            Assert.True(Flag);
        }
        public void ShouldReceiveUtf8MultibyteCharacters()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            var events  = new Queue <object>();
            var result  = string.Empty;
            var correct = new string[]
            {
                "てすと",
                "Я Б Г Д Ж Й",
                "Ä ä Ü ü ß",
                "李O四",
                "utf8 — string"
            };
            var i = 0;

            var options = CreateOptions();

            options.Transports = new List <string>()
            {
                "polling"
            };
            var uri = CreateUri();

            socket = IO.Socket(uri, options);

            socket.On("takeUtf8", (data) =>
            {
                events.Enqueue(data);
                i++;
                log.Info(string.Format("takeUtf8 data={0} i={1}", (string)data, i));
                result = "1234";
                if (i >= correct.Length)
                {
                    ManualResetEvent.Set();
                }
            });


            socket.Emit("getUtf8");
            ManualResetEvent.WaitOne(15000);
            socket.Close();
            var j = 0;

            foreach (var obj in events)
            {
                var str = (string)obj;
                Assert.Equal(correct[j++], str);
            }
            Assert.Equal("1234", result);
        }
        public void ShouldSendBinaryDataAsAnArraybufferMixedWithJson()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);
            Flag             = false;

            var buf  = System.Text.Encoding.UTF8.GetBytes("howdy");
            var jobj = new JObject();

            jobj.Add("hello", "lol");
            jobj.Add("message", buf);
            jobj.Add("goodbye", "gotcha");

            var options = CreateOptions();
            //options.Transports = ImmutableList.Create<string>(Polling.NAME);

            var uri = CreateUri();

            socket = IO.Socket(uri, options);
            socket.On("jsonbuff-ack", () =>
            {
                Flag = true;
                ManualResetEvent.Set();
            });

            socket.On(SOCKETNET35.Socket.EVENT_DISCONNECT, () =>
            {
                log.Info("EVENT_DISCONNECT");
            });

            socket.Emit("jsonbuff", jobj);

            ManualResetEvent.WaitOne(15000);
            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));

            log.Info("About to wait 1sec");

            //Task.Delay(1000).Wait();
            log.Info("About to call close");
            socket.Close();
            //Task.Delay(1000).Wait();
            Assert.True(Flag);
            log.Info("Finish");
        }
        public void ShouldWorkWithAcks()
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            log.Info("Start");
            ManualResetEvent = new ManualResetEvent(false);

            var result = "";

            var options = CreateOptions();
            var uri     = CreateUri();

            socket = IO.Socket(uri, options);
            socket.Emit("ack");

            socket.On("ack", (cb) =>
            {
                var obj  = new JObject();
                obj["b"] = true;
                var iack = (IAck)cb;
                iack.Call(5, obj);
            });

            socket.On("got it",
                      (data) =>
            {
                log.Info("got it");
                Assert.Null(data);
                result = "got it";
                ManualResetEvent.Set();
            });

            ManualResetEvent.WaitOne(15000);
            socket.Close();
            Assert.Equal("got it", result);
        }
 private void OnConnect()
 {
     Connected = true;
     Debug.Log("SocketService connected: " + Id.ToString());
     MainSocket.Emit("hi", "Connect Hi from " + Id.ToString());
 }