Java Code Examples for org.springframework.web.reactive.socket.WebSocketMessage#getType()
The following examples show how to use
org.springframework.web.reactive.socket.WebSocketMessage#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NettyWebSocketSessionSupport.java From spring-analysis-note with MIT License | 6 votes |
protected WebSocketFrame toFrame(WebSocketMessage message) { ByteBuf byteBuf = NettyDataBufferFactory.toByteBuf(message.getPayload()); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { return new TextWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { return new BinaryWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { return new PingWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { return new PongWebSocketFrame(byteBuf); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } }
Example 2
Source File: UndertowWebSocketSession.java From spring-analysis-note with MIT License | 6 votes |
@Override protected boolean sendMessage(WebSocketMessage message) throws IOException { ByteBuffer buffer = message.getPayload().asByteBuffer(); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { getSendProcessor().setReadyToSend(false); String text = new String(buffer.array(), StandardCharsets.UTF_8); WebSockets.sendText(text, getDelegate(), new SendProcessorCallback(message.getPayload())); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { getSendProcessor().setReadyToSend(false); WebSockets.sendBinary(buffer, getDelegate(), new SendProcessorCallback(message.getPayload())); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { getSendProcessor().setReadyToSend(false); WebSockets.sendPing(buffer, getDelegate(), new SendProcessorCallback(message.getPayload())); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { getSendProcessor().setReadyToSend(false); WebSockets.sendPong(buffer, getDelegate(), new SendProcessorCallback(message.getPayload())); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } return true; }
Example 3
Source File: StandardWebSocketSession.java From spring-analysis-note with MIT License | 6 votes |
@Override protected boolean sendMessage(WebSocketMessage message) throws IOException { ByteBuffer buffer = message.getPayload().asByteBuffer(); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { getSendProcessor().setReadyToSend(false); String text = new String(buffer.array(), StandardCharsets.UTF_8); getDelegate().getAsyncRemote().sendText(text, new SendProcessorCallback()); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { getSendProcessor().setReadyToSend(false); getDelegate().getAsyncRemote().sendBinary(buffer, new SendProcessorCallback()); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { getDelegate().getAsyncRemote().sendPing(buffer); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { getDelegate().getAsyncRemote().sendPong(buffer); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } return true; }
Example 4
Source File: JettyWebSocketSession.java From spring-analysis-note with MIT License | 6 votes |
@Override protected boolean sendMessage(WebSocketMessage message) throws IOException { ByteBuffer buffer = message.getPayload().asByteBuffer(); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { getSendProcessor().setReadyToSend(false); String text = new String(buffer.array(), StandardCharsets.UTF_8); getDelegate().getRemote().sendString(text, new SendProcessorCallback()); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { getSendProcessor().setReadyToSend(false); getDelegate().getRemote().sendBytes(buffer, new SendProcessorCallback()); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { getDelegate().getRemote().sendPing(buffer); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { getDelegate().getRemote().sendPong(buffer); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } return true; }
Example 5
Source File: NettyWebSocketSessionSupport.java From java-technology-stack with MIT License | 6 votes |
protected WebSocketFrame toFrame(WebSocketMessage message) { ByteBuf byteBuf = NettyDataBufferFactory.toByteBuf(message.getPayload()); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { return new TextWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { return new BinaryWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { return new PingWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { return new PongWebSocketFrame(byteBuf); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } }
Example 6
Source File: UndertowWebSocketSession.java From java-technology-stack with MIT License | 6 votes |
@Override protected boolean sendMessage(WebSocketMessage message) throws IOException { ByteBuffer buffer = message.getPayload().asByteBuffer(); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { getSendProcessor().setReadyToSend(false); String text = new String(buffer.array(), StandardCharsets.UTF_8); WebSockets.sendText(text, getDelegate(), new SendProcessorCallback(message.getPayload())); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { getSendProcessor().setReadyToSend(false); WebSockets.sendBinary(buffer, getDelegate(), new SendProcessorCallback(message.getPayload())); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { getSendProcessor().setReadyToSend(false); WebSockets.sendPing(buffer, getDelegate(), new SendProcessorCallback(message.getPayload())); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { getSendProcessor().setReadyToSend(false); WebSockets.sendPong(buffer, getDelegate(), new SendProcessorCallback(message.getPayload())); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } return true; }
Example 7
Source File: StandardWebSocketSession.java From java-technology-stack with MIT License | 6 votes |
@Override protected boolean sendMessage(WebSocketMessage message) throws IOException { ByteBuffer buffer = message.getPayload().asByteBuffer(); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { getSendProcessor().setReadyToSend(false); String text = new String(buffer.array(), StandardCharsets.UTF_8); getDelegate().getAsyncRemote().sendText(text, new SendProcessorCallback()); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { getSendProcessor().setReadyToSend(false); getDelegate().getAsyncRemote().sendBinary(buffer, new SendProcessorCallback()); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { getDelegate().getAsyncRemote().sendPing(buffer); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { getDelegate().getAsyncRemote().sendPong(buffer); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } return true; }
Example 8
Source File: JettyWebSocketSession.java From java-technology-stack with MIT License | 6 votes |
@Override protected boolean sendMessage(WebSocketMessage message) throws IOException { ByteBuffer buffer = message.getPayload().asByteBuffer(); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { getSendProcessor().setReadyToSend(false); String text = new String(buffer.array(), StandardCharsets.UTF_8); getDelegate().getRemote().sendString(text, new SendProcessorCallback()); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { getSendProcessor().setReadyToSend(false); getDelegate().getRemote().sendBytes(buffer, new SendProcessorCallback()); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { getDelegate().getRemote().sendPing(buffer); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { getDelegate().getRemote().sendPong(buffer); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } return true; }
Example 9
Source File: VertxWebSocketSession.java From vertx-spring-boot with Apache License 2.0 | 6 votes |
private void messageHandler(WebSocketBase socket, WebSocketMessage message) { if (message.getType() == WebSocketMessage.Type.TEXT) { String payload = message.getPayloadAsText(); socket.writeTextMessage(payload); } else { Buffer buffer = bufferConverter.toBuffer(message.getPayload()); if (message.getType() == WebSocketMessage.Type.PING) { socket.writePing(buffer); } else if (message.getType() == WebSocketMessage.Type.PONG) { socket.writePong(buffer); } else { socket.writeBinaryMessage(buffer); } } }