List of usage examples for io.netty.handler.codec.http.websocketx TextWebSocketFrame text
public String text()
From source file:adalightserver.http.HttpServer.java
License:Apache License
private void handleWebSocketFrame(ChannelHandlerContext ctx, TextWebSocketFrame frame) { // System.out.println("Received: " + frame.text()); JsonSlurper slurper = new JsonSlurper(); Object o = slurper.parseText(frame.text()); if (!(o instanceof Map<?, ?>)) return;//from w ww . ja v a2 s . c o m Map<?, ?> msg = (Map<?, ?>) o; if (!msg.containsKey("type")) return; Object typeO = msg.get("type"); if (!(typeO instanceof String)) return; String type = (String) typeO; if (type.equals("rq")) { // Received a request // Need id, method name and data if (!msg.containsKey("id") || !msg.containsKey("method") || !msg.containsKey("data")) return; Object idObj = msg.get("id"); long id; if (idObj instanceof Integer) { id = (Integer) idObj; } else if (idObj instanceof Long) { id = (Long) idObj; } else return; Object methodObj = msg.get("method"); if (!(methodObj instanceof String)) return; String method = (String) methodObj; Object dataObj = msg.get("data"); Map<?, ?> data; if (dataObj instanceof Map<?, ?>) data = (Map<?, ?>) dataObj; else data = null; handleRequest(ctx, id, method, data); } }
From source file:be.yildizgames.module.network.netty.server.SessionWebSocketMessageHandler.java
License:MIT License
@Override public void channelRead0(final ChannelHandlerContext ctx, final TextWebSocketFrame message) throws Exception { this.getSession().ifPresent(s -> this.handler.processMessages(s, message.text())); }
From source file:ca.lambtoncollege.netty.webSocket.ClientHandlerWebSocket.java
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { Channel ch = ctx.channel();/*from ww w .j av a 2 s .co m*/ if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); System.out.println("WebSocket Client connected!"); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; System.out.println("WebSocket Client received message: " + textFrame.text()); } else if (frame instanceof PongWebSocketFrame) { System.out.println("WebSocket Client received pong"); } else if (frame instanceof CloseWebSocketFrame) { System.out.println("WebSocket Client received closing"); ch.close(); } }
From source file:cn.easyplay.proxy.WebSocketClientHandler.java
License:Apache License
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ctx.channel(), (FullHttpResponse) msg); LOGGER.debug("WebSocket Client connected!"); handshakeFuture.setSuccess();/*www.ja v a 2 s. co m*/ return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; // frame telnetChannel.writeAndFlush(textFrame.text()); LOGGER.debug("WebSocket Client received message: " + textFrame.text()); } else if (frame instanceof PongWebSocketFrame) { LOGGER.debug("WebSocket Client received pong"); } else if (frame instanceof CloseWebSocketFrame) { LOGGER.debug("WebSocket Client received closing"); ctx.close(); telnetChannel.close(); } }
From source file:cn.npt.net.handler.BaseWebSocketClientHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { Channel ch = ctx.channel();/*from ww w .j a va 2s . co m*/ if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); log.info("WebSocket Client connected to " + ctx.channel()); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; doReceive(textFrame.text()); } else if (frame instanceof PongWebSocketFrame) { //System.out.println("WebSocket Client received pong"); } else if (frame instanceof CloseWebSocketFrame) { log.info("WebSocket Client received closing"); ch.close(); } }
From source file:cn.scujcc.bug.bitcoinplatformandroid.util.socket.websocket.WebSocketClientHandler.java
License:Apache License
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { Channel ch = ctx.channel();/*from w w w . j a v a 2 s . c o m*/ moniter.updateTime(); if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); System.out.println("WebSocket Client connected!"); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; service.onReceive(textFrame.text()); } else if (frame instanceof BinaryWebSocketFrame) { BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame; service.onReceive(decodeByteBuff(binaryFrame.content())); } else if (frame instanceof PongWebSocketFrame) { System.out.println("WebSocket Client received pong"); } else if (frame instanceof CloseWebSocketFrame) { System.out.println("WebSocket Client received closing"); ch.close(); } }
From source file:com.athena.dolly.websocket.client.test.WebSocketClientHandler.java
License:Apache License
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { Channel ch = ctx.channel();/*from w w w.j a v a 2s.c o m*/ if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); System.out.println("WebSocket Client connected!"); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; System.out.println("WebSocket Client received message: " + textFrame.text()); } else if (frame instanceof PongWebSocketFrame) { System.out.println("WebSocket Client received pong"); } else if (frame instanceof CloseWebSocketFrame) { System.out.println("WebSocket Client received closing"); ch.close(); } }
From source file:com.cmz.http.websocketx.client.WebSocketClientHandler.java
License:Apache License
@Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { Channel ch = ctx.channel();/*from ww w. j a va2s .c o m*/ if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); System.out.println("WebSocket Client connected!"); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; System.out.println("WebSocket Client received message: " + textFrame.text()); } else if (frame instanceof PongWebSocketFrame) { System.out.println("WebSocket Client received pong"); } else if (frame instanceof CloseWebSocketFrame) { System.out.println("WebSocket Client received closing"); ch.close(); } }
From source file:com.codebullets.external.party.simulator.connections.websocket.outbound.NettyWebSocketClientHandler.java
License:Apache License
@Override public void messageReceived(final ChannelHandlerContext ctx, final Object msg) throws Exception { Channel ch = ctx.channel();//from ww w . ja v a2 s. c o m if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); LOG.info("WebSocket client {} connected.", connectionName); connectionMonitor.connectionEstablished(getContext(ctx)); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; LOG.debug("WebSocket client {} received message: " + textFrame.text(), connectionName); connectionMonitor.messageReceived(MessageReceivedEvent.create(getContext(ctx), textFrame.text())); } else if (frame instanceof BinaryWebSocketFrame) { ByteBuf buffer = Unpooled.buffer(frame.content().capacity()); buffer.writeBytes(frame.content()); byte[] data = buffer.array(); LOG.debug("WebSocket client {} received buffer with length " + data.length, connectionName); connectionMonitor.messageReceived(MessageReceivedEvent.create(getContext(ctx), buffer)); } else if (frame instanceof PingWebSocketFrame) { LOG.trace("WebSocket client {} received ping.", connectionName); ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); } else if (frame instanceof CloseWebSocketFrame) { LOG.debug("WebSocket client {} received closing frame.", connectionName); ch.close(); } }
From source file:com.fanavard.challenge.client.websocket.WebSocketClientHandler.java
License:Apache License
@Override public void messageReceived(ChannelHandlerContext ctx, Object msg) { Channel ch = ctx.channel();//from w w w. ja v a 2s .c o m if (!handshaker.isHandshakeComplete()) { handshaker.finishHandshake(ch, (FullHttpResponse) msg); System.out.println("WebSocket Client connected!"); handshakeFuture.setSuccess(); return; } if (msg instanceof FullHttpResponse) { FullHttpResponse response = (FullHttpResponse) msg; throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')'); } WebSocketFrame frame = (WebSocketFrame) msg; if (frame instanceof TextWebSocketFrame) { TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; System.out.println("WebSocket Client received message: " + textFrame.text()); } else if (frame instanceof PongWebSocketFrame) { System.out.println("WebSocket Client received pong"); } else if (frame instanceof CloseWebSocketFrame) { System.out.println("WebSocket Client received closing"); ch.close(); } }