List of usage examples for org.springframework.web.socket TextMessage TextMessage
public TextMessage(byte[] payload)
From source file:cn.com.inhand.devicenetworks.ap.websocket.WSDNAccessPoint.java
/** * ?Inboxlogout//w ww. j a v a 2s . c o m * * @param logout */ private void onUnkownMsg(DNMessage msg, WebSocketSession session, WSDNSession wsdnsn) throws IOException, PacketException { List list = new ArrayList(); list.add(new Parameter("result", "23009")); list.add(new Parameter("reason", "" + wsdnsn.getAssetid() + "@" + wsdnsn.getLast_msg())); DNMessage ack = new DNMessage(msg.getName(), "response", msg.getTxid(), list); session.sendMessage(new TextMessage(new String(parser.wrap(ack)))); list.clear(); wsdnsn.setSession(session); wsdnsn.setLast_msg(System.currentTimeMillis()); }
From source file:ch.rasc.wampspring.pubsub.PubSubReplyAnnotationTest.java
@Test public void testUnsubscribe1() throws InterruptedException, ExecutionException, IOException, TimeoutException { CompletableFutureWebSocketHandler result = new CompletableFutureWebSocketHandler(this.jsonFactory); try (WebSocketSession webSocketSession = startWebSocketSession(result)) { SubscribeMessage subscribeMsg = new SubscribeMessage("replyTo1"); webSocketSession.sendMessage(new TextMessage(subscribeMsg.toJson(this.jsonFactory))); UnsubscribeMessage unsubscribeMessage = new UnsubscribeMessage("pubSubService.incomingUnsubscribe1"); webSocketSession.sendMessage(new TextMessage(unsubscribeMessage.toJson(this.jsonFactory))); EventMessage event = (EventMessage) result.getWampMessage(); assertThat(event.getTopicURI()).isEqualTo("replyTo1"); assertThat(event.getEvent()).isEqualTo("returnUnsub1"); }/*from w ww.j a v a 2 s .c om*/ }
From source file:es.urjc.etsii.code.UserSession.java
private void addOnIceCandidateListener() { webRtcEndpoint.addOnIceCandidateListener(new EventListener<OnIceCandidateEvent>() { @Override/*from w w w . j a v a 2s . c o m*/ public void onEvent(OnIceCandidateEvent event) { JsonObject response = new JsonObject(); response.addProperty("id", "iceCandidate"); response.add("candidate", JsonUtils.toJsonObject(event.getCandidate())); handler.sendMessage(wsSession, sessionNumber, new TextMessage(response.toString())); } }); }
From source file:fi.vtt.nubomedia.kurento.Ar3DHandler.java
private void sendError(WebSocketSession session, String message) { try {//w w w .j a v a2 s. c om JsonObject response = new JsonObject(); response.addProperty("id", "error"); response.addProperty("message", message); session.sendMessage(new TextMessage(response.toString())); } catch (IOException e) { log.error("Exception sending message", e); } }
From source file:ch.rasc.wampspring.pubsub.PubSubReplyAnnotationTest.java
@Test public void testUnsubscribe2() throws InterruptedException, ExecutionException, IOException, TimeoutException { CompletableFutureWebSocketHandler result1 = new CompletableFutureWebSocketHandler(this.jsonFactory); CompletableFutureWebSocketHandler result2 = new CompletableFutureWebSocketHandler(this.jsonFactory); try (WebSocketSession webSocketSession1 = startWebSocketSession(result1); WebSocketSession webSocketSession2 = startWebSocketSession(result2)) { SubscribeMessage subscribeMsg = new SubscribeMessage("replyTo2"); webSocketSession1.sendMessage(new TextMessage(subscribeMsg.toJson(this.jsonFactory))); webSocketSession2.sendMessage(new TextMessage(subscribeMsg.toJson(this.jsonFactory))); UnsubscribeMessage unsubscribeMessage = new UnsubscribeMessage("pubSubService.incomingUnsubscribe2"); webSocketSession1.sendMessage(new TextMessage(unsubscribeMessage.toJson(this.jsonFactory))); EventMessage event = (EventMessage) result2.getWampMessage(); assertThat(event.getTopicURI()).isEqualTo("replyTo2"); assertThat(event.getEvent()).isEqualTo("returnUnsub2"); event = null;//from w w w. j a v a 2s . c o m try { event = (EventMessage) result1.getWampMessage(); Assert.fail("call has to timeout"); } catch (Exception e) { assertThat(e).isInstanceOf(TimeoutException.class); } assertThat(event).isNull(); } }
From source file:com.zb.app.websocket.server.WebSocketServerHandler.java
/** * ?????/*from w w w . j a va2 s. co m*/ * * @param receiverMessage * @param session */ public void clientHeartbeat(SocketMessage<?> receiverMessage, WebSocketSession session) { ClientWrapper cw = receiverMessage.getClientInfo(); SessionWrapper sw = getSessionInfo(session); String json = JsonResultUtils.createJsonResult(ResultCode.HEARTBEAT, "$zuobian$", "Server zxc,hello world!"); if (session == null) { return; } if (session != null && !session.isOpen()) { removeSession(session); } try { session.sendMessage(new TextMessage(json)); if (sw != null) { sw.setLastHeartbeatTime(System.currentTimeMillis()); } logger.debug("clientHeartbeat sessionId={} ,mId={},cId={}, date={}", sw.getId(), cw.getmId(), cw.getWebUser().getcId(), DateViewTools.formatFullDate(new Date())); } catch (Exception e) { if (System.currentTimeMillis() - sw.getLastHeartbeatTime() >= 1000 * 60 * 5) { // 5??Client removeSession(session); } logger.debug("clientHeartbeat send errorsessionId={} ,mId={},cId={}, date={}", sw.getId(), cw.getmId(), cw.getWebUser().getcId(), DateViewTools.formatFullDate(new Date())); } }
From source file:fi.vtt.nubomedia.kurento.Ar3DHandler.java
private void getStats(WebSocketSession session) { try {/*from w w w .j av a 2 s .c o m*/ Map<String, Stats> wr_stats = webRtcEndpoint.getStats(); //System.err.println("GET STATS..." + wr_stats); for (Stats s : wr_stats.values()) { //System.err.println("STATS:" + s); switch (s.getType()) { case endpoint: { //System.err.println("STATS endpoint"); EndpointStats end_stats = (EndpointStats) s; double e2eVideLatency = end_stats.getVideoE2ELatency() / 1000000; smart("***SMART E2E\t", e2eVideLatency); JsonObject response = new JsonObject(); response.addProperty("id", "videoE2Elatency"); response.addProperty("message", e2eVideLatency); synchronized (session) { session.sendMessage(new TextMessage(response.toString())); } } break; case inboundrtp: { RTCInboundRTPStreamStats stats = (RTCInboundRTPStreamStats) s; //System.err.println(stats.getJitter()); } break; case outboundrtp: { RTCOutboundRTPStreamStats stats = (RTCOutboundRTPStreamStats) s; // System.err.println(stats.getRoundTripTime()); // JsonObject response = new JsonObject(); // response.addProperty("id", "videoE2Elatency"); // response.addProperty("message", stats.getRoundTripTime()); // synchronized (session) { // session.sendMessage(new TextMessage(response.toString())); // } } break; default: //System.err.println("STATS DEFAULTS: " + s.getType() + "#" + s.getClass()); break; } } } catch (IOException e) { log.error("Exception sending message", e); } }
From source file:ch.rasc.wampspring.pubsub.PubSubReplyAnnotationTest.java
@Test public void testUnsubscribe3() throws InterruptedException, ExecutionException, IOException, TimeoutException { CompletableFutureWebSocketHandler result = new CompletableFutureWebSocketHandler(this.jsonFactory); try (WebSocketSession webSocketSession = startWebSocketSession(result)) { SubscribeMessage subscribeMsg = new SubscribeMessage("replyTo3"); webSocketSession.sendMessage(new TextMessage(subscribeMsg.toJson(this.jsonFactory))); UnsubscribeMessage unsubscribeMessage = new UnsubscribeMessage("incomingUnsub3"); webSocketSession.sendMessage(new TextMessage(unsubscribeMessage.toJson(this.jsonFactory))); EventMessage event = (EventMessage) result.getWampMessage(); assertThat(event.getTopicURI()).isEqualTo("replyTo3"); assertThat(event.getEvent()).isEqualTo("returnUnsub3"); }//w w w .j av a 2 s .c om }
From source file:ch.rasc.wampspring.pubsub.PubSubReplyAnnotationTest.java
@Test public void testUnsubscribe4() throws InterruptedException, ExecutionException, IOException, TimeoutException { CompletableFutureWebSocketHandler result = new CompletableFutureWebSocketHandler(3, this.jsonFactory); try (WebSocketSession webSocketSession = startWebSocketSession(result)) { webSocketSession/*from ww w . j a v a 2 s. c o m*/ .sendMessage(new TextMessage(new SubscribeMessage("replyTo4_1").toJson(this.jsonFactory))); webSocketSession .sendMessage(new TextMessage(new SubscribeMessage("replyTo4_2").toJson(this.jsonFactory))); webSocketSession .sendMessage(new TextMessage(new SubscribeMessage("replyTo4_3").toJson(this.jsonFactory))); UnsubscribeMessage unsubscribeMessage = new UnsubscribeMessage("incomingUnsub4"); webSocketSession.sendMessage(new TextMessage(unsubscribeMessage.toJson(this.jsonFactory))); List<WampMessage> resultList = result.getWampMessages(); for (int i = 0; i < resultList.size(); i++) { EventMessage eventMessage = (EventMessage) resultList.get(i); assertThat(eventMessage.getTopicURI()).isEqualTo("replyTo4_" + (i + 1)); assertThat(eventMessage.getEvent()).isEqualTo("returnUnsub4"); } } }
From source file:ch.rasc.wampspring.pubsub.PubSubReplyAnnotationTest.java
@Test public void testUnsubscribe5() throws InterruptedException, ExecutionException, IOException, TimeoutException { CompletableFutureWebSocketHandler result1 = new CompletableFutureWebSocketHandler(this.jsonFactory); CompletableFutureWebSocketHandler result2 = new CompletableFutureWebSocketHandler(this.jsonFactory); try (WebSocketSession webSocketSession1 = startWebSocketSession(result1); WebSocketSession webSocketSession2 = startWebSocketSession(result2)) { webSocketSession1/* w ww. j a v a2 s . co m*/ .sendMessage(new TextMessage(new SubscribeMessage("replyTo5").toJson(this.jsonFactory))); webSocketSession2 .sendMessage(new TextMessage(new SubscribeMessage("replyTo5").toJson(this.jsonFactory))); UnsubscribeMessage unsubscribeMessage = new UnsubscribeMessage("incomingUnsub5"); webSocketSession1.sendMessage(new TextMessage(unsubscribeMessage.toJson(this.jsonFactory))); EventMessage event1 = (EventMessage) result1.getWampMessage(); assertThat(event1.getTopicURI()).isEqualTo("replyTo5"); assertThat(event1.getEvent()).isEqualTo("returnUnsub5"); EventMessage event = null; try { event = (EventMessage) result2.getWampMessage(); Assert.fail("call has to timeout"); } catch (Exception e) { assertThat(e).isInstanceOf(TimeoutException.class); } assertThat(event).isNull(); } }