public void TestOnHandler()
        {
            AddIn addInOut = null;

            AutoResetEvent responseEvent = new AutoResetEvent(false);

            var websocket = new JsonWebSocket(string.Format("{0}:{1}/websocket", Host, m_WebSocketServer.Config.Port), "basic");
            websocket.Opened += new EventHandler(websocket_Opened);
            websocket.Closed += new EventHandler(websocket_Closed);
            websocket.On<AddIn>("ECHOJSON", (e) =>
                {
                    addInOut = e;
                    responseEvent.Set();
                });

            websocket.Open();

            if (!m_OpenedEvent.WaitOne(1000))
                Assert.Fail("Failed to Opened session ontime");

            Assert.AreEqual(WebSocketState.Open, websocket.State);


            for (var i = 0; i < 20; i++)
            {
                AddIn addIn = new AddIn { A = m_Random.Next(1, 9999), B = m_Random.Next(1, 9999) };

                websocket.Send("ECHOJSON", addIn);

                if (!responseEvent.WaitOne(1000))
                    Assert.Fail("Failed to get response ontime");

                Assert.AreEqual(addIn.A, addInOut.A);
                Assert.AreEqual(addIn.B, addInOut.B);
            }

            websocket.Close();

            if (!m_CloseEvent.WaitOne(1000))
                Assert.Fail("Failed to close session ontime");

            Assert.AreEqual(WebSocketState.Closed, websocket.State);
        }
        public void TestLongQueryHandler()
        {
            AutoResetEvent responseEvent = new AutoResetEvent(false);

            var websocket = new JsonWebSocket(string.Format("{0}:{1}/websocket", Host, m_WebSocketServer.Config.Port), "basic");
            websocket.Opened += new EventHandler(websocket_Opened);
            websocket.Closed += new EventHandler(websocket_Closed);

            websocket.Open();

            if (!m_OpenedEvent.WaitOne(1000))
                Assert.Fail("Failed to Opened session ontime");

            Assert.AreEqual(WebSocketState.Open, websocket.State);


            for (var i = 0; i < 2; i++)
            {
                AddOut addOut = null;

                AddIn addIn = new AddIn { A = m_Random.Next(1, 9999), B = m_Random.Next(1, 9999) };

                websocket.Query<AddOut>("ADDX", addIn, (o) =>
                {
                    addOut = o;
                    responseEvent.Set();
                });

                if (!responseEvent.WaitOne(4000))
                    Assert.Fail("Failed to get response ontime");

                Assert.AreEqual(addIn.A + addIn.B, addOut.Result);
            }

            websocket.Close();

            if (!m_CloseEvent.WaitOne(1000))
                Assert.Fail("Failed to close session ontime");

            Assert.AreEqual(WebSocketState.Closed, websocket.State);
        }