Netty5源码分析--2.客户端启动过程
实例 样例代码来自于 io.netty.example.telnet.TelnetClient ,完整样例请参考NettyExample工程。 客户端和服务端比较相似,所以本篇会在一定程度上略去重复的部分,以减少篇幅。 public void run() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); b.group(group) .channel(NioSocketChannel.class) .handler(new TelnetClientInitializer()); // Start the connection attempt. Channel ch = b.connect(host, port).sync().channel(); // Read commands from the stdin. ChannelFuture lastWriteFuture = null; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for (;;) { String line = in.readLine(); if (line