flying_wind 发表于 2013-1-4 02:20:50

netty源代码解析(2)——客户端流程

<div id="cnblogs_post_body">前一篇文章分析了netty的服务端流程,接下来分析一下客户端的大致流程,客户端启动代码如下
<div class="cnblogs_code">ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),                Executors.newCachedThreadPool()));      bootstrap.setPipelineFactory(new ChannelPipelineFactory() {            @Override            public ChannelPipeline getPipeline() throws Exception {                ChannelPipeline pipleline = pipeline();                pipleline.addLast("encode", new ObjectEncoder(1048576 * 16));                pipleline.addLast("decode", new ObjectDecoder(1048576 * 16, ClassResolvers.weakCachingConcurrentResolver(null)));                pipleline.addLast("handler", handler);                return pipleline;            }      });      bootstrap.setOption("receiveBufferSize", 1048576 * 64);      bootstrap.setOption("child.tcpNoDelay", true); //关闭Nagle算法      //tcp定期发送心跳包 比如IM里边定期探测对方是否下线      //只有tcp长连接下才有意义//      bootstrap.setOption("child.keepAlive", true);      ChannelFuture future = bootstrap.connect(new InetSocketAddress(address, port));      Channel channel = future.awaitUninterruptibly().getChannel();
页: [1]
查看完整版本: netty源代码解析(2)——客户端流程