use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project benchmark by seelunzi.
the class ClientIniter method initChannel.
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast("stringD", new StringDecoder());
pipeline.addLast("stringC", new StringEncoder());
pipeline.addLast("http", new HttpClientCodec());
pipeline.addLast("chat", new ChatClientHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project benchmark by seelunzi.
the class ServerIniterHandler method initChannel.
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast("docode", new StringDecoder());
pipeline.addLast("encode", new StringEncoder());
pipeline.addLast("chat", new ChatServerHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project pancm_project by xuwujing.
the class NettyServerFilter method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline ph = ch.pipeline();
// 以("\n")为结尾分割的 解码器
// ph.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
// 解码和编码,应和客户端一致
ph.addLast("decoder", new StringDecoder());
ph.addLast("encoder", new StringEncoder());
// 服务端业务逻辑
ph.addLast("handler", new NettyServerHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project pancm_project by xuwujing.
the class NettyClientFilter method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline ph = ch.pipeline();
/*
* 解码和编码,应和服务端一致
* */
// ph.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
ph.addLast("decoder", new StringDecoder());
ph.addLast("encoder", new StringEncoder());
// 客户端的逻辑
ph.addLast("handler", new NettyClientHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project pancm_project by xuwujing.
the class NettyServerDemo4 method start.
/**
* Start.
*/
public void start() {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap sbs = new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).localAddress(new InetSocketAddress(port)).childHandler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new StringDecoder());
// 绑定自定义业务逻辑
p.addLast(new NettyServerHandlerDemo4());
}
}).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
// 绑定端口,开始接收进来的连接
ChannelFuture future = sbs.bind(port).sync();
System.out.println("Netty服务端启动成功,端口为: " + port);
// 释放监听
future.channel().closeFuture().sync();
} catch (Exception e) {
// 释放资源
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
Aggregations