@Override public String toString() { return getClass().getSimpleName() + "(data: " + getBinaryData() + ')'; }
/** * Creates a new pong frame with the specified binary data * * @param finalFragment * flag indicating if this frame is the final fragment * @param rsv * reserved bits used for protocol extensions * @param binaryData * the content of the frame. */ public PongWebSocketFrame(boolean finalFragment, int rsv, ChannelBuffer binaryData) { setFinalFragment(finalFragment); setRsv(rsv); setBinaryData(binaryData); }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (e.getMessage() instanceof WebSocketFrame) { WebSocketFrame frame = (WebSocketFrame) e.getMessage(); if (frame instanceof CloseWebSocketFrame) { WebSocketServerHandshaker handshaker = getHandshaker(ctx); handshaker.close(ctx.getChannel(), (CloseWebSocketFrame) frame); return; } else if (frame instanceof PingWebSocketFrame) { ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData())); return; } } ctx.sendUpstream(e); }
/** * Creates a new empty pong frame. */ public PongWebSocketFrame() { setBinaryData(ChannelBuffers.EMPTY_BUFFER); }
@Override public WebSocket sendPong(byte[] payload) { channel.write(new PongWebSocketFrame(wrappedBuffer(payload))); return this; }
/** * Creates a new pong frame with the specified binary data. * * @param binaryData * the content of the frame. */ public PongWebSocketFrame(ChannelBuffer binaryData) { setBinaryData(binaryData); }
return new PongWebSocketFrame(frameFinalFlag, frameRsv, framePayload);
@Override public WebSocket sendPong(byte[] payload) { channel.write(new PongWebSocketFrame(wrappedBuffer(payload))); return this; }
@Override public WebSocket sendPong(byte[] payload) { channel.write(new PongWebSocketFrame(wrappedBuffer(payload))); return this; }
@Override public WebSocket sendPong(byte[] payload) { channel.write(new PongWebSocketFrame(wrappedBuffer(payload))); return this; }
private void handleWebSocketFrame(ChannelHandlerContext ctx, Channel channel, WebSocketFrame frame) throws IOException { // Check for closing frame if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.getChannel(), (CloseWebSocketFrame) frame); return; } else if (frame instanceof PingWebSocketFrame) { ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData())); return; } else if (!(frame instanceof TextWebSocketFrame)) { throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass().getName())); } String request = ((TextWebSocketFrame) frame).getText(); logger.debug(String.format("Channel %s received '%s'", ctx.getChannel().getId(), request)); SockJsMessage jsMessage = new SockJsMessage(request); ctx.sendUpstream(new UpstreamMessageEvent(channel, jsMessage, channel.getRemoteAddress())); }
public void frame(WebSocketServerHandshaker handshaker, WebSocketFrame frame, ChannelHandlerContext context) { Channel channel = context.getChannel(); if (frame instanceof TextWebSocketFrame) { text((TextWebSocketFrame) frame, channel); } else if (handshaker != null && frame instanceof CloseWebSocketFrame) { handshaker.close(context.getChannel(), (CloseWebSocketFrame) frame); presence(Presence.DISCONNECTED, null, channel); } else if (frame instanceof PingWebSocketFrame) { channel.write(new PongWebSocketFrame(frame.getBinaryData())); } }
private void websocketFrameReceived(ChannelHandlerContext ctx, WebSocketFrame webSocketFrame) { Http.Inbound inbound = channels.get(ctx); // Check for closing frame if (webSocketFrame instanceof CloseWebSocketFrame) { this.handshaker.close(ctx.getChannel(), (CloseWebSocketFrame) webSocketFrame); } else if (webSocketFrame instanceof PingWebSocketFrame) { ctx.getChannel().write(new PongWebSocketFrame(webSocketFrame.getBinaryData())); } else if (webSocketFrame instanceof BinaryWebSocketFrame) { inbound._received(new Http.WebSocketFrame(webSocketFrame.getBinaryData().array())); } else if (webSocketFrame instanceof TextWebSocketFrame) { inbound._received(new Http.WebSocketFrame(((TextWebSocketFrame) webSocketFrame).getText())); } }
return; } else if (frame instanceof PingWebSocketFrame) { ctx.getChannel().write(new PongWebSocketFrame(frame.getBinaryData())); return; } else if (frame instanceof TextWebSocketFrame) {