public class Client4 {
public static void main(String[] args) {
//worker负责读写数据
EventLoopGroup worker = new NioEventLoopGroup();
long st = System.currentTimeMillis();
try {
//辅助启动类
Bootstrap bootstrap = new Bootstrap();
//设置线程池
bootstrap.group(worker);
//设置socket工厂
bootstrap.channel(NioSocketChannel.class);
/**
* *******************************************************************
* 如果不设置超时,连接会一直占用本地线程,端口,连接客户端一多,会导致本地端口用尽及CPU压力
*/
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000);
//设置管道
bootstrap.handler(new ChannelInitializer() {
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
//获取管道
ChannelPipeline pipeline = socketChanne