当前位置: 首页>>代码示例>>Java>>正文


Java LineBasedFrameDecoder类代码示例

本文整理汇总了Java中io.netty.handler.codec.LineBasedFrameDecoder的典型用法代码示例。如果您正苦于以下问题:Java LineBasedFrameDecoder类的具体用法?Java LineBasedFrameDecoder怎么用?Java LineBasedFrameDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LineBasedFrameDecoder类属于io.netty.handler.codec包,在下文中一共展示了LineBasedFrameDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serverBootStrapWithOptionsTest

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
@Test
public void serverBootStrapWithOptionsTest() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
	LinkedHashMap<String, Object> channelHandlerOptions = new LinkedHashMap<String, Object>();
	
	channelHandlerOptions.put("lineFrame", new LineBasedFrameDecoder(2000));
	channelHandlerOptions.put("decoder", new StringDecoder());
	channelHandlerOptions.put("encoder", new StringEncoder());
	channelHandlerOptions.put("handler", new ChannelInboundHandlerAdapter() {
		
		@Override
		public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
			log.info("Message Received and forward to ConsumerProcessor. Msg -> {}", msg);
		}
	});
	
	Server server = BootStrap.builder()
			.port(5252)
			.options(channelHandlerOptions)
			.messageConsumer(msg -> log.info(msg))
			.build();
	
	assertNotNull(server);
}
 
开发者ID:Creativesource-Sys,项目名称:jfast,代码行数:24,代码来源:ServerTest.java

示例2: connect

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
public void connect(int port, String host) throws InterruptedException {
	
	EventLoopGroup group = new NioEventLoopGroup();
	try{
		Bootstrap b = new Bootstrap();
		b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true)
		.handler(new ChannelInitializer<SocketChannel>() {

			@Override
			protected void initChannel(SocketChannel ch) throws Exception {
				ch.pipeline().addLast(new LineBasedFrameDecoder(1024));
				ch.pipeline().addLast(new StringDecoder());
				ch.pipeline().addLast(new TimeClientHandler());
			}
			
		});
		
		//发送异步链接操作
		ChannelFuture f = b.connect(host, port).sync();
		//等待客户端链路关闭
		f.channel().closeFuture().sync();
	}finally{
		group.shutdownGracefully();
	}
	
}
 
开发者ID:hdcuican,项目名称:java_learn,代码行数:27,代码来源:TimeClient.java

示例3: addByteDecoderWhenNoLeft

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
@Test
public void addByteDecoderWhenNoLeft() throws Exception {

	channel.pipeline()
	       .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
	       });
	ChannelHandler decoder = new LineBasedFrameDecoder(12);

	testContext.addHandlerLast("decoder", decoder)
	           .addHandlerFirst("decoder$extract",
			           NettyPipeline.inboundHandler(ADD_EXTRACTOR));

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList("decoder$extract",
					"decoder",
					NettyPipeline.ReactiveBridge,
					"DefaultChannelPipeline$TailContext#0"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:20,代码来源:NettyContextTest.java

示例4: addByteDecoderWhenNoRight

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
@Test
public void addByteDecoderWhenNoRight() throws Exception {

	channel.pipeline()
	       .addLast(NettyPipeline.HttpCodec, new ChannelHandlerAdapter() {
	       });
	ChannelHandler decoder = new LineBasedFrameDecoder(12);

	testContext.addHandlerLast("decoder", decoder)
	           .addHandlerFirst("decoder$extract",
			           NettyPipeline.inboundHandler(ADD_EXTRACTOR));

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList(NettyPipeline.HttpCodec,
					"decoder$extract",
					"decoder",
					"DefaultChannelPipeline$TailContext#0"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:20,代码来源:NettyContextTest.java

示例5: addByteDecoderWhenFullReactorPipeline

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
@Test
public void addByteDecoderWhenFullReactorPipeline() throws Exception {

	channel.pipeline()
	       .addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
	       .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
	       .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
	       });
	ChannelHandler decoder = new LineBasedFrameDecoder(12);

	testContext.addHandlerLast("decoder", decoder)
	           .addHandlerFirst("decoder$extract",
			           NettyPipeline.inboundHandler(ADD_EXTRACTOR));

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList(NettyPipeline.HttpCodec,
					NettyPipeline.HttpServerHandler,
					"decoder$extract",
					"decoder",
					NettyPipeline.ReactiveBridge,
					"DefaultChannelPipeline$TailContext#0"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:24,代码来源:NettyContextTest.java

示例6: addByteEncoderWhenNoLeft

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
@Test
public void addByteEncoderWhenNoLeft() throws Exception {

	channel.pipeline()
	       .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
	       });
	ChannelHandler encoder = new LineBasedFrameDecoder(12);

	testContext.addHandlerFirst("encoder", encoder);

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList("encoder",
					NettyPipeline.ReactiveBridge,
					"DefaultChannelPipeline$TailContext#0"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:17,代码来源:NettyContextTest.java

示例7: addByteEncoderWhenNoRight

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
@Test
public void addByteEncoderWhenNoRight() throws Exception {

	channel.pipeline()
	       .addLast(NettyPipeline.HttpCodec, new ChannelHandlerAdapter() {
	       });
	ChannelHandler encoder = new LineBasedFrameDecoder(12);

	testContext.addHandlerFirst("encoder", encoder);

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList(NettyPipeline.HttpCodec,
					"encoder",
					"DefaultChannelPipeline$TailContext#0"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:17,代码来源:NettyContextTest.java

示例8: addByteEncoderWhenFullReactorPipeline

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
@Test
public void addByteEncoderWhenFullReactorPipeline() throws Exception {

	channel.pipeline()
	       .addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
	       .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
	       .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
	       });
	ChannelHandler encoder = new LineBasedFrameDecoder(12);

	testContext.addHandlerFirst("encoder", encoder);

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList(NettyPipeline.HttpCodec,
					NettyPipeline.HttpServerHandler,
					"encoder",
					NettyPipeline.ReactiveBridge,
					"DefaultChannelPipeline$TailContext#0"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:21,代码来源:NettyContextTest.java

示例9: addSeveralByteEncodersWhenCodec

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
@Test
public void addSeveralByteEncodersWhenCodec() throws Exception {
	ChannelHandler encoder1 = new LineBasedFrameDecoder(12);
	ChannelHandler encoder2 = new LineBasedFrameDecoder(13);

	channel.pipeline()
	       .addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
	       .addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
	       .addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
	       });

	testContext.addHandlerFirst("encoder1", encoder1)
	           .addHandlerFirst("encoder2", encoder2);

	assertEquals(channel.pipeline()
	                    .names(),
			Arrays.asList(NettyPipeline.HttpCodec,
					NettyPipeline.HttpServerHandler,
					"encoder2",
					"encoder1",
					NettyPipeline.ReactiveBridge,
					"DefaultChannelPipeline$TailContext#0"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:24,代码来源:NettyContextTest.java

示例10: flushOnComplete

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
@Test
public void flushOnComplete() {

	Flux<String> test = Flux.range(0, 100)
	                        .map(n -> String.format("%010d", n));

	NettyContext c = HttpServer.create(0)
	                           .newHandler((req, resp) -> resp.sendString(test.map(s -> s + "\n")))
	                           .block(Duration.ofSeconds(30));

	Flux<String> client = HttpClient.create(c.address()
	                                         .getPort())
	                                .get("/")
	                                .block(Duration.ofSeconds(30))
	                                .addHandler(new LineBasedFrameDecoder(10))
	                                .receive()
	                                .asString();

	StepVerifier.create(client)
	            .expectNextSequence(test.toIterable())
	            .expectComplete()
	            .verify(Duration.ofSeconds(30));

	c.dispose();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:26,代码来源:HttpServerTests.java

示例11: main

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    EventLoopGroup group = new OioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group)
         .channel(RxtxChannel.class)
         .handler(new ChannelInitializer<RxtxChannel>() {
             @Override
             public void initChannel(RxtxChannel ch) throws Exception {
                 ch.pipeline().addLast(
                     new LineBasedFrameDecoder(32768),
                     new StringEncoder(),
                     new StringDecoder(),
                     new RxtxClientHandler()
                 );
             }
         });

        ChannelFuture f = b.connect(new RxtxDeviceAddress(PORT)).sync();

        f.channel().closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:26,代码来源:RxtxClient.java

示例12: initChannel

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    LineBasedFrameDecoder lineDecoder = new LineBasedFrameDecoder(MAX_LINE_LENGTH);
    StringDecoder stringDecoder = new StringDecoder(CHARSET); //FIXME: Should only split on CRLF, not on LF alone
    MessageDecoder messageDecoder = new MessageDecoder();
    MessageHandler messageHandler = new MessageHandler(handler);

    StringEncoder stringEncoder = new StringEncoder(CHARSET);
    MessageEncoder messageEncoder = new MessageEncoder();

    IdleStateHandler idleHandler = new IdleStateHandler(IDLE_TIMEOUT, 0, 0);

    // Inbound goes from first to last, outbound goes from last to first.
    // i.e. the outside is on the left/top, the inside is on the right/bottom
    ch.pipeline().addLast(lineDecoder).addLast(stringDecoder).addLast(messageDecoder).addLast(idleHandler).addLast(messageHandler)
            .addLast(stringEncoder).addLast(messageEncoder);

}
 
开发者ID:Wolf480pl,项目名称:ircd4j,代码行数:19,代码来源:IRCChannelInitializer.java

示例13: main

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    EventLoopGroup group = new OioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group)
                .channel(RxtxChannel.class)
                .handler(new ChannelInitializer<RxtxChannel>() {
                    @Override
                    public void initChannel(RxtxChannel ch) throws Exception {
                        ch.pipeline().addLast(
                                new LineBasedFrameDecoder(32768),
                                new StringEncoder(),
                                new StringDecoder(),
                                new RxtxClientHandler()
                        );
                    }
                });

        ChannelFuture f = b.connect(new RxtxDeviceAddress(PORT)).sync();

        f.channel().closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:26,代码来源:RxtxClient.java

示例14: run

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
public void run(String host, int port) throws Exception {

        EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(group)
                    .channel(NioSocketChannel.class)
                    .remoteAddress(host, port)
                    .handler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws Exception {
                            ch.pipeline().addLast(new LineBasedFrameDecoder(20))
                                    .addLast(new StringDecoder())
                                    .addLast(new DelimitedClientHandler());
                        }
                    });

            ChannelFuture cf = bootstrap.connect().sync();
            cf.channel().closeFuture().sync();
        } finally {
            group.shutdownGracefully();
        }
    }
 
开发者ID:edgar615,项目名称:javase-study,代码行数:24,代码来源:DelimitedChient.java

示例15: main

import io.netty.handler.codec.LineBasedFrameDecoder; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    EventLoopGroup group = new OioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group)
         .channel(RxtxChannel.class)
         .handler(new ChannelInitializer<RxtxChannel>() {
             @Override
             public void initChannel(RxtxChannel ch) throws Exception {
                 ch.pipeline().addLast(
                     new LineBasedFrameDecoder(32768),
                     new StringEncoder(),
                     new StringDecoder(),
                     new RxtxClientHandler()
                 );
             }
         });

        ChannelFuture f = b.connect(new RxtxDeviceAddress("/dev/ttyUSB0")).sync();

        f.channel().closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:26,代码来源:RxtxClient.java


注:本文中的io.netty.handler.codec.LineBasedFrameDecoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。