List of usage examples for io.netty.channel ChannelHandlerContext fireChannelRead
@Override ChannelHandlerContext fireChannelRead(Object msg);
From source file:org.jfxvnc.net.rfb.codec.ProtocolHandler.java
License:Apache License
@Override protected void decode(final ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception { if (msg instanceof ImageRect) { render.render((ImageRect) msg, () -> { // logger.debug("render completed"); // sendFramebufferUpdateRequest(ctx, true, 0, 0, // serverInit.getFrameBufferWidth(), // serverInit.getFrameBufferHeight()); });// ww w.j av a 2 s . com return; } if (msg instanceof ServerDecoderEvent) { render.eventReceived((ServerDecoderEvent) msg); return; } if (!(msg instanceof ServerInitEvent)) { logger.error("unknown message: {}", msg); ctx.fireChannelRead(msg); return; } serverInit = (ServerInitEvent) msg; logger.debug("handshake completed with {}", serverInit); FrameDecoderHandler frameHandler = new FrameDecoderHandler(serverInit.getPixelFormat()); if (!frameHandler.isPixelFormatSupported()) { ProtocolException e = new ProtocolException(String.format("pixelformat: (%s bpp) not supported yet", serverInit.getPixelFormat().getBitPerPixel())); exceptionCaught(ctx, e); return; } ChannelPipeline cp = ctx.pipeline(); cp.addBefore(ctx.name(), "rfb-encoding-encoder", new PreferedEncodingEncoder()); PreferedEncoding prefEncodings = getPreferedEncodings(frameHandler.getSupportedEncodings()); ctx.write(prefEncodings); cp.addBefore(ctx.name(), "rfb-pixelformat-encoder", new PixelFormatEncoder()); ctx.write(serverInit.getPixelFormat()); ctx.flush(); cp.addBefore(ctx.name(), "rfb-frame-handler", frameHandler); cp.addBefore(ctx.name(), "rfb-keyevent-encoder", new KeyButtonEventEncoder()); cp.addBefore(ctx.name(), "rfb-pointerevent-encoder", new PointerEventEncoder()); cp.addBefore(ctx.name(), "rfb-cuttext-encoder", new ClientCutTextEncoder()); render.eventReceived(getConnectInfoEvent(ctx, prefEncodings)); render.registerInputEventListener(event -> ctx.writeAndFlush(event, ctx.voidPromise())); logger.debug("request full framebuffer update"); sendFramebufferUpdateRequest(ctx, false, 0, 0, serverInit.getFrameBufferWidth(), serverInit.getFrameBufferHeight()); logger.trace("channel pipeline: {}", cp.toMap().keySet()); }
From source file:org.jupiter.transport.netty.handler.IdleStateChecker.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (readerIdleTimeMillis > 0 || allIdleTimeMillis > 0) { firstReaderIdleEvent = firstAllIdleEvent = true; reading = true; // make hb for firstReaderIdleEvent and firstAllIdleEvent }/*from www. j a va2 s . com*/ ctx.fireChannelRead(msg); }
From source file:org.kaaproject.kaa.server.transports.http.transport.netty.RequestDecoder.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpObject httpObject) throws Exception { DecoderResult result = httpObject.getDecoderResult(); if (!result.isSuccess()) { throw new BadRequestException(result.cause()); }//from w w w. jav a 2 s. c o m Attribute<UUID> sessionUuidAttr = ctx.channel().attr(AbstractNettyServer.UUID_KEY); if (httpObject instanceof HttpRequest) { HttpRequest httpRequest = (HttpRequest) httpObject; LOG.trace("Session: {} got valid HTTP request:\n{}", sessionUuidAttr.get().toString(), httpRequest.headers().toString()); if (httpRequest.getMethod().equals(HttpMethod.POST)) { String uri = httpRequest.getUri(); AbstractCommand cp = (AbstractCommand) commandFactory.getCommandProcessor(uri); cp.setSessionUuid(sessionUuidAttr.get()); cp.setRequest(httpRequest); cp.parse(); ctx.fireChannelRead(cp); } else { LOG.error("Got invalid HTTP method: expecting only POST"); throw new BadRequestException( "Incorrect method " + httpRequest.getMethod().toString() + ", expected POST"); } } else { LOG.warn("Session: {} got invalid HTTP object:\n{}", sessionUuidAttr.get().toString(), httpObject); } }
From source file:org.kobeyoung81.socksproxy.DirectClientHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ctx.fireChannelRead(msg); UnpooledUnsafeDirectByteBuf buffer = (UnpooledUnsafeDirectByteBuf) msg; System.out.println("Content:" + " <<< " + buffer.toString(Charset.defaultCharset())); }
From source file:org.lanternpowered.pingy.PingyLegacyHandler.java
License:MIT License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg0) throws Exception { final ByteBuf msg = (ByteBuf) msg0; boolean legacy = false; msg.markReaderIndex();//w w w . j a v a 2 s. c om try { // Try first as a legacy ping message int messageId = msg.readUnsignedByte(); // Make sure that old clients don't attempt to login if (messageId == 0x02) { legacy = this.tryHandleLegacyJoin(ctx, msg); } else if (messageId == 0xfe) { legacy = this.tryHandleLegacyPing(ctx, msg); } } catch (Exception e) { } if (!legacy) { msg.resetReaderIndex(); ctx.pipeline().remove(this); ctx.fireChannelRead(msg); } else { msg.release(); } }
From source file:org.lanternpowered.server.network.pipeline.LegacyProtocolHandler.java
License:MIT License
@Override public void channelRead(ChannelHandlerContext ctx, Object object) throws Exception { final LanternServer server = this.session.getServer(); ByteBuf buf = (ByteBuf) object;//from w ww .j a va2s . co m buf.markReaderIndex(); // Whether it was a valid legacy message boolean legacy = false; try { final int messageId = buf.readUnsignedByte(); // Old client's are not so smart, make sure that // they don't attempt to login if (messageId == 0x02) { int protocol = buf.readByte(); // Protocol version int value = buf.readShort(); // Check the length if (value < 0 || value > 16) { return; } buf.readBytes(value << 1); // Username value = buf.readShort(); // Check the length if (value < 0 || value > 255) { return; } buf.readBytes(value << 1); // Host address buf.readInt(); // Port if (buf.readableBytes() > 0) { return; } legacy = true; sendDisconnectMessage(ctx, LanternTexts.toPlain(t("multiplayer.disconnect.outdated_client", Lantern.getGame().getPlatform().getMinecraftVersion().getName()))); final MinecraftVersion clientVersion = Lantern.getGame().getMinecraftVersionCache() .getVersionOrUnknown(protocol, true); if (clientVersion == LanternMinecraftVersion.UNKNOWN_LEGACY) { Lantern.getLogger().debug( "Client with unknown legacy protocol version {} attempted to join the server.", protocol); } else { Lantern.getLogger().debug( "Client with legacy protocol version {} (mc-version {}) attempted to join the server.", protocol, clientVersion.getName()); } return; } // Check for the ping message id. if (messageId != 0xfe) { return; } int readable = buf.readableBytes(); boolean full = false; // The version used to ping the server int protocol = V1_3_2_PROTOCOL; // Versions 1.4 - 1.5.x + 1.6 - Can request full data. if (readable > 0) { // Is always 1 if (buf.readUnsignedByte() != 1) { return; } full = true; protocol = V1_5_2_PROTOCOL; } // The virtual address that was used to join the server InetSocketAddress virtualAddress = null; // Version 1.6 - Used extra data. if (readable > 1) { if (buf.readUnsignedByte() != 0xfa) { return; } byte[] bytes = new byte[buf.readShort() << 1]; buf.readBytes(bytes); if (!new String(bytes, StandardCharsets.UTF_16BE).equals("MC|PingHost")) { return; } // Not used buf.readShort(); // The protocol version is present protocol = buf.readUnsignedByte(); // There is extra host and port data if (protocol >= 73) { bytes = new byte[buf.readShort() << 1]; buf.readBytes(bytes); final String host = new String(bytes, StandardCharsets.UTF_16BE); final int port = buf.readInt(); virtualAddress = InetSocketAddress.createUnresolved(host, port); } readable = buf.readableBytes(); if (readable > 0) { Lantern.getLogger().warn("Trailing bytes on a legacy ping message: {}b", readable); } } final MinecraftVersion clientVersion = Lantern.getGame().getMinecraftVersionCache() .getVersionOrUnknown(protocol, true); if (clientVersion == LanternMinecraftVersion.UNKNOWN) { Lantern.getLogger().debug("Client with unknown legacy protocol version {} pinged the server.", protocol); } // The message was successfully decoded as a legacy one legacy = true; final MinecraftVersion serverVersion = Lantern.getGame().getPlatform().getMinecraftVersion(); Text description = server.getMotd(); final InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress(); final LanternStatusClient client = new LanternStatusClient(address, clientVersion, virtualAddress); final ClientPingServerEvent.Response.Players players = LanternStatusHelper.createPlayers(server); final LanternStatusResponse response = new LanternStatusResponse(serverVersion, server.getFavicon(), description, players); final ClientPingServerEvent event = SpongeEventFactory .createClientPingServerEvent(Cause.source(client).build(), client, response); Sponge.getEventManager().post(event); // Cancelled, we are done here if (event.isCancelled()) { ctx.channel().close(); return; } description = response.getDescription(); int online = players.getOnline(); final int max = players.getMax(); // The players should be hidden, this will replace the player count // with ??? if (!response.getPlayers().isPresent()) { online = -1; } final String data; if (full) { final String description0 = getFirstLine( TextSerializers.LEGACY_FORMATTING_CODE.serialize(description)); // 1. This value is always 1. // 2. The protocol version, just use a value out of range // of the available ones. // 3. The version/name string of the server. // 4. The motd of the server. In legacy format. // 5. The online players // 6. The maximum amount of players data = String.format("\u00A7%s\u0000%s\u0000%s\u0000%s\u0000%s\u0000%s", 1, 127, response.getVersion().getName(), description0, online, max); } else { final String description0 = getFirstLine(TextSerializers.PLAIN.serialize(description)); // 1. The motd of the server. In legacy format. // 2. The online players // 3. The maximum amount of players data = String.format("%s\u00A7%s\u00A7%s", description0, online, max); } sendDisconnectMessage(ctx, data); } catch (Exception ignore) { } finally { if (legacy) { buf.release(); } else { buf.resetReaderIndex(); ctx.channel().pipeline().remove(this); ctx.fireChannelRead(buf); } } }
From source file:org.neo4j.bolt.transport.SocketTransportHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ByteBuf) { ByteBuf buffer = (ByteBuf) msg;//from ww w . jav a2 s. co m if (protocol == null) { chooseProtocolVersion(ctx, buffer); } else { protocol.handle(ctx, buffer); } } else { ctx.fireChannelRead(msg); } }
From source file:org.neo4j.bolt.transport.WebSocketFrameTranslator.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof BinaryWebSocketFrame) { ctx.fireChannelRead(((BinaryWebSocketFrame) msg).content()); } else {// w w w .ja va 2 s. c o m ctx.fireChannelRead(msg); } }
From source file:org.onesec.raven.rtp.InboundChannelInitializator.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof DatagramPacket) { final InetSocketAddress senderSocket = ((DatagramPacket) msg).sender(); if (logger.isTraceEnabled()) logger.debug("Received initial packet from ({})", senderSocket.toString()); if (sender == null || sender.equals(senderSocket.getAddress())) { initChannel(senderSocket, ctx.channel()); ctx.pipeline().remove(this); ctx.fireChannelRead(msg); }// w w w . j a v a 2 s .c o m } }
From source file:org.onesec.raven.rtp.InboundPacketFilter.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (((DatagramPacket) msg).sender().equals(sender)) ctx.fireChannelRead(msg); }