学习netty,做一些记录,简单的客户端/服务端示例
客户端:
public class NettyClient { public static void main(String[] args) throws InterruptedException { EventLoopGroup group = new NioEventLoopGroup(); //创建客户端启动对象,与服务端不同,非ServerBootstrap Bootstrap bootstrap = new Bootstrap(); try { bootstrap.group(group) .channel(NioSocketChannel.class)// 使用 NioSocketChannel 作为客户端的通道实现 .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel socketChannel) throws Exception { //加入自定义处理器 socketChannel.pipeline().addLast(new NettyClientHandler()); } }); System.out.printf("netty client start"); //链接服务端 ChannelFutu