Files
jsowell-charger-web/jsowell-netty/src/main/java/com/jsowell/netty/client/NettyClientChannelInitializer.java

24 lines
909 B
Java
Raw Normal View History

2023-03-04 16:29:55 +08:00
package com.jsowell.netty.client;
import com.jsowell.netty.server.yunkuaichong.NettyServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;
/**
* 客户端初始化客户端与服务器端连接一旦创建这个类中方法就会被回调设置出站编码器和入站解码器客户端服务端编解码要一致
*/
public class NettyClientChannelInitializer extends ChannelInitializer<SocketChannel> {
@Override
protected void initChannel(SocketChannel channel) throws Exception {
channel.pipeline().addLast("decoder",new StringDecoder(CharsetUtil.UTF_8));
channel.pipeline().addLast("encoder",new StringEncoder(CharsetUtil.UTF_8));
channel.pipeline().addLast(new NettyServerHandler());
}
}