io.netty.handler.codec.Delimiters Java Examples
The following examples show how to use
io.netty.handler.codec.Delimiters.
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: SecureChatServerInitializer.java From netty-4.1.22 with Apache License 2.0 | 7 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add SSL handler first to encrypt and decrypt everything. // In this example, we use a bogus certificate in the server side // and accept any invalid certificates in the client side. // You will need something more complicated to identify both // and server in the real world. pipeline.addLast(sslCtx.newHandler(ch.alloc())); // On top of the SSL handler, add the text line codec. pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // and then business logic. pipeline.addLast(new SecureChatServerHandler()); }
Example #2
Source File: MonitorServer.java From Jupiter with Apache License 2.0 | 6 votes |
@Override public ChannelFuture bind(SocketAddress localAddress) { ServerBootstrap boot = bootstrap(); initChannelFactory(); boot.childHandler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ch.pipeline().addLast( new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()), new StringDecoder(StandardCharsets.UTF_8), encoder, handler); } }); setOptions(); return boot.bind(localAddress); }
Example #3
Source File: TelnetServerInitializer.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); } // Add the text line codec combination first, pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); // the encoder and decoder are static as these are sharable pipeline.addLast(DECODER); pipeline.addLast(ENCODER); // and then business logic. pipeline.addLast(SERVER_HANDLER); }
Example #4
Source File: TelnetClientInitializer.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc(), TelnetClient.HOST, TelnetClient.PORT)); } // Add the text line codec combination first, pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(DECODER); pipeline.addLast(ENCODER); // and then business logic. pipeline.addLast(CLIENT_HANDLER); }
Example #5
Source File: TelnetClientInitializer.java From tools-journey with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc(), TelnetClient.HOST, TelnetClient.PORT)); } // Add the text line codec combination first, pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(DECODER); pipeline.addLast(ENCODER); // and then business logic. pipeline.addLast(CLIENT_HANDLER); }
Example #6
Source File: TelnetServerInitializer.java From tools-journey with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); } // Add the text line codec combination first, pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); // the encoder and decoder are static as these are sharable pipeline.addLast(DECODER); pipeline.addLast(ENCODER); // and then business logic. pipeline.addLast(SERVER_HANDLER); }
Example #7
Source File: SecureChatClientInitializer.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add SSL handler first to encrypt and decrypt everything. // In this example, we use a bogus certificate in the server side // and accept any invalid certificates in the client side. // You will need something more complicated to identify both // and server in the real world. pipeline.addLast(sslCtx.newHandler(ch.alloc(), SecureChatClient.HOST, SecureChatClient.PORT)); // On top of the SSL handler, add the text line codec. pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // and then business logic. pipeline.addLast(new SecureChatClientHandler()); }
Example #8
Source File: DelimiterBasedFrameDecoderTest.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@Test public void testFailSlowTooLongFrameRecovery() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new DelimiterBasedFrameDecoder(1, true, false, Delimiters.nulDelimiter())); for (int i = 0; i < 2; i ++) { ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 })); try { assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0 }))); fail(DecoderException.class.getSimpleName() + " must be raised."); } catch (TooLongFrameException e) { // Expected } ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A', 0 })); ByteBuf buf = releaseLater((ByteBuf) ch.readInbound()); assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); } }
Example #9
Source File: DelimiterBasedFrameDecoderTest.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@Test public void testFailFastTooLongFrameRecovery() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new DelimiterBasedFrameDecoder(1, Delimiters.nulDelimiter())); for (int i = 0; i < 2; i ++) { try { assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 }))); fail(DecoderException.class.getSimpleName() + " must be raised."); } catch (TooLongFrameException e) { // Expected } ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 'A', 0 })); ByteBuf buf = releaseLater((ByteBuf) ch.readInbound()); assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); } }
Example #10
Source File: SecureChatServerInitializer.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add SSL handler first to encrypt and decrypt everything. // In this example, we use a bogus certificate in the server side // and accept any invalid certificates in the client side. // You will need something more complicated to identify both // and server in the real world. pipeline.addLast(sslCtx.newHandler(ch.alloc())); // On top of the SSL handler, add the text line codec. pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // and then business logic. pipeline.addLast(new SecureChatServerHandler()); }
Example #11
Source File: SecureChatClientInitializer.java From julongchain with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // 添加SSL用于加密每一个步骤. // 在本次演示中我们在服务端使用了一张虚拟的证书,可以接收任何有效的客户端证书. // 但在真实场景中你需要一个更复杂的客户端和服务端标记. pipeline.addLast(sslCtx.newHandler(ch.alloc(), SecureChatClient.HOST, SecureChatClient.PORT)); // SSL之上添加编解码处理. pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // 处理业务逻辑. pipeline.addLast(new SecureChatClientHandler()); }
Example #12
Source File: SecureChatServerInitializer.java From julongchain with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // 添加SSL用于加密每一个步骤. // 在本次演示中我们在服务端使用了一张虚拟的证书,可以接收任何有效的客户端证书. // 但在真实场景中你需要一个更复杂的客户端和服务端标记. pipeline.addLast(sslCtx.newHandler(ch.alloc())); // SSL之上添加编解码处理. pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // 处理业务逻辑. pipeline.addLast(new SecureChatServerHandler()); }
Example #13
Source File: SecureChatClientInitializer.java From x-pipe with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add SSL handler first to encrypt and decrypt everything. // In this example, we use a bogus certificate in the server side // and accept any invalid certificates in the client side. // You will need something more complicated to identify both // and server in the real world. pipeline.addLast(createSslHandler(getClientSSLContext())); // On top of the SSL handler, add the text line codec. pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // and then business logic. pipeline.addLast(new SecureChatClientHandler()); }
Example #14
Source File: SecureChatServerInitializer.java From x-pipe with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add SSL handler first to encrypt and decrypt everything. // In this example, we use a bogus certificate in the server side // and accept any invalid certificates in the client side. // You will need something more complicated to identify both // and server in the real world. pipeline.addLast(createSslHandler(initSSLContext())); // On top of the SSL handler, add the text line codec. pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // and then business logic. pipeline.addLast(new SecureChatServerHandler()); }
Example #15
Source File: DelimiterBasedFrameDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Test public void testFailFastTooLongFrameRecovery() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new DelimiterBasedFrameDecoder(1, Delimiters.nulDelimiter())); for (int i = 0; i < 2; i ++) { try { assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 }))); fail(DecoderException.class.getSimpleName() + " must be raised."); } catch (TooLongFrameException e) { // Expected } ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 'A', 0 })); ByteBuf buf = ch.readInbound(); assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); buf.release(); } }
Example #16
Source File: DelimiterBasedFrameDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Test public void testFailSlowTooLongFrameRecovery() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new DelimiterBasedFrameDecoder(1, true, false, Delimiters.nulDelimiter())); for (int i = 0; i < 2; i ++) { ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 })); try { assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0 }))); fail(DecoderException.class.getSimpleName() + " must be raised."); } catch (TooLongFrameException e) { // Expected } ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A', 0 })); ByteBuf buf = ch.readInbound(); assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1)); buf.release(); } }
Example #17
Source File: CarbonServer.java From disthene with MIT License | 6 votes |
public void run() throws InterruptedException { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new DelimiterBasedFrameDecoder(MAX_FRAME_LENGTH, false, Delimiters.lineDelimiter())); p.addLast(new CarbonServerHandler(bus, configuration.getCarbon().getBaseRollup())); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { logger.error(cause); super.exceptionCaught(ctx, cause); } }); // Start the server. b.bind(configuration.getCarbon().getBind(), configuration.getCarbon().getPort()).sync(); }
Example #18
Source File: TelnetClientInitializer.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc(), TelnetClient.HOST, TelnetClient.PORT)); } // Add the text line codec combination first, pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(DECODER); pipeline.addLast(ENCODER); // and then business logic. pipeline.addLast(CLIENT_HANDLER); }
Example #19
Source File: TelnetServerInitializer.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); } // Add the text line codec combination first, pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); // the encoder and decoder are static as these are sharable pipeline.addLast(DECODER); pipeline.addLast(ENCODER); // and then business logic. pipeline.addLast(SERVER_HANDLER); }
Example #20
Source File: SecureChatClientInitializer.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add SSL handler first to encrypt and decrypt everything. // In this example, we use a bogus certificate in the server side // and accept any invalid certificates in the client side. // You will need something more complicated to identify both // and server in the real world. pipeline.addLast(sslCtx.newHandler(ch.alloc(), SecureChatClient.HOST, SecureChatClient.PORT)); // On top of the SSL handler, add the text line codec. pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // and then business logic. pipeline.addLast(new SecureChatClientHandler()); }
Example #21
Source File: ServerHandlersInit.java From x-pipe with Apache License 2.0 | 5 votes |
protected void initChannel(SocketChannel socketChannel) throws Exception { SslHandler sslHandler = SSLHandlerProvider.getSSLHandler(); ChannelPipeline pipeline = socketChannel.pipeline(); pipeline.addLast(sslHandler); pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); // and then business logic. pipeline.addLast(new SecureChatServerHandler()); }
Example #22
Source File: ProxyForwardingVoteSource.java From NuVotifier with GNU General Public License v3.0 | 5 votes |
private void forwardVote(final BackendServer server, final Vote v, final int tries) { nettyBootstrap.get() .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel channel) { channel.pipeline().addLast(new DelimiterBasedFrameDecoder(256, true, Delimiters.lineDelimiter())); channel.pipeline().addLast(new ReadTimeoutHandler(5, TimeUnit.SECONDS)); channel.pipeline().addLast(STRING_DECODER); channel.pipeline().addLast(new VotifierProtocol2Encoder(server.key)); channel.pipeline().addLast(new VotifierProtocol2HandshakeHandler(v, new VotifierResponseHandler() { @Override public void onSuccess() { if (plugin.isDebug()) { plugin.getPluginLogger().info("Successfully forwarded vote " + v + " to " + server.address + "."); } } @Override public void onFailure(Throwable error) { handleFailure(server, v, error, tries); } }, plugin)); } }) .connect(server.address) .addListener((ChannelFutureListener) future -> { if (!future.isSuccess()) { handleFailure(server, v, future.cause(), tries); } }); }
Example #23
Source File: ManagerConnector.java From JgFramework with Apache License 2.0 | 5 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(new StringDecoder()); pipeline.addLast(new StringEncoder()); pipeline.addLast(new ManagerHandler()); }
Example #24
Source File: UDTClientServerConnectionTest.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override public void run() { final Bootstrap boot = new Bootstrap(); final ThreadFactory clientFactory = new DefaultThreadFactory("client"); final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, clientFactory, NioUdtProvider.BYTE_PROVIDER); try { boot.group(connectGroup) .channelFactory(NioUdtProvider.BYTE_CONNECTOR) .handler(new ChannelInitializer<UdtChannel>() { @Override protected void initChannel(final UdtChannel ch) throws Exception { final ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast("decoder", new StringDecoder( CharsetUtil.UTF_8)); pipeline.addLast("encoder", new StringEncoder( CharsetUtil.UTF_8)); pipeline.addLast("handler", new ClientHandler()); } }); channel = boot.connect(host, port).sync().channel(); isRunning = true; log.info("Client ready."); waitForRunning(false); log.info("Client closing..."); channel.close().sync(); isShutdown = true; log.info("Client is done."); } catch (final Throwable e) { log.error("Client failed.", e); } finally { connectGroup.shutdownGracefully().syncUninterruptibly(); } }
Example #25
Source File: Server.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
private static ChannelFuture sendResponse(final ChannelHandlerContext ctx, final String response) { ByteBuf buf = ctx.alloc().buffer(); buf.writeBytes(response.getBytes(WireProtocol.CHARSET)); ctx.write(buf); return ctx.writeAndFlush(Delimiters.lineDelimiter()[0]); }
Example #26
Source File: Server.java From ARCHIVE-wildfly-swarm with Apache License 2.0 | 5 votes |
private void setupPipeline(final ChannelPipeline pipeline) { pipeline.addLast(NAME_CHANNEL_HANDLER_FRAME_DECODER, new DelimiterBasedFrameDecoder(2000, Delimiters.lineDelimiter())); pipeline.addLast(NAME_CHANNEL_HANDLER_STRING_DECODER, new StringDecoder(WireProtocol.CHARSET)); pipeline.addLast(NAME_CHANNEL_HANDLER_COMMAND, new StringCommandHandler()); }
Example #27
Source File: TelnetServerInitializer.java From netty.book.kor with MIT License | 5 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add the text line codec combination first, pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); // the encoder and decoder are static as these are sharable pipeline.addLast(DECODER); pipeline.addLast(ENCODER); // and then business logic. pipeline.addLast(SERVER_HANDLER); }
Example #28
Source File: TelnetServerInitializerV3.java From netty.book.kor with MIT License | 5 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add the text line codec combination first, pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters .lineDelimiter())); // the encoder and decoder are static as these are sharable pipeline.addLast(DECODER); pipeline.addLast(ENCODER); // and then business logic. pipeline.addLast(SERVER_HANDLER); }
Example #29
Source File: TelnetServerInitializer.java From netty.book.kor with MIT License | 5 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); pipeline.addLast(DECODER); pipeline.addLast(ENCODER); pipeline.addLast(SERVER_HANDLER); }
Example #30
Source File: GraphiteInitializer.java From newts with Apache License 2.0 | 5 votes |
@Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); // Add the text line codec combination first, pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); // the encoder and decoder are static as these are sharable pipeline.addLast(DECODER); pipeline.addLast(ENCODER); // and then business logic. pipeline.addLast(new GraphiteHandler(m_repository, this)); }