protected override void ExecuteAsyncJsonCommand(WebSocketSession session, string token, AddIn commandInfo) { var result = new AddOut { Result = commandInfo.A + commandInfo.B }; Thread.Sleep(2000); this.SendJsonMessage(session, token, result); }
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); }