use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project tech by ffyyhh995511.
the class HelloClientInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
/*
* 这个地方的 必须和服务端对应上。否则无法正常解码和编码
*
* 解码和编码 我将会在下一张为大家详细的讲解。再次暂时不做详细的描述
*
* */
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
// 客户端的逻辑
pipeline.addLast("handler", new HelloClientHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project sidewinder by srotya.
the class TestGraphiteDecoder method testHandler.
@Test
public void testHandler() throws IOException {
EmbeddedChannel ch = new EmbeddedChannel(new StringDecoder(), new GraphiteDecoder("test", engine, null));
ch.writeInbound(Unpooled.copiedBuffer("app1.server1.jvm.heap.max 233123 1497720452", Charset.defaultCharset()));
ch.readInbound();
verify(engine, times(1)).writeDataPoint("test", "heap", "max", Arrays.asList("app1", "server1", "jvm"), ((long) 1497720452) * 1000, 233123);
ch.close();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project tutorials-java by Artister.
the class ClientChannelInitializer method initChannel.
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
// 客户端的handler
// 先调用handler在ChannnelActive方法中调用fireChannelActive会激活handler1
pipeline.addLast("handler", new HwClientHandler());
pipeline.addLast("handler1", new BaseClientHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project tutorials-java by Artister.
the class ServerChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
// 字符串解码 和 编码
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
// 字符长度
pipeline.addLast(new LineBasedFrameDecoder(2048));
// 自己的逻辑Handler
pipeline.addLast("handler", new HelloWordServerHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project tutorials-java by Artister.
the class NettyServer method service.
public static void service() throws Exception {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup);
bootstrap.channel(NioServerSocketChannel.class);
bootstrap.childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
// TODO Auto-generated method stub
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
pipeline.addLast(new LengthFieldPrepender(4));
pipeline.addLast(new StringDecoder(CharsetUtil.UTF_8));
pipeline.addLast(new StringEncoder(CharsetUtil.UTF_8));
pipeline.addLast(new TcpServerHandler());
}
});
ChannelFuture f = bootstrap.bind(IP, PORT).sync();
f.channel().closeFuture().sync();
System.out.println("TCP服务器已启动");
}
Aggregations