ney 4.x 源码分析
服务端需要经过 socket、bind、accept、read、write 等步骤,客户端需要经过
socket、connect、read、write 等步骤,后续此系列文章会对每一个步骤如何发生进行分析。
以下是服务端和客户端的测试代码,后面的分析以这份代码为基础,目前使用的 Netty 的版本是
4.0.4.Final 及以上
Java 代码<<
1. 服务端:<<
2. /*
3. *Copyright2012TheNettyProject
4. *
5. *TheNettyProjectlicensesthisfiletoyouundertheApacheLicense,
6. *version2.0(the"License");youmaynotusethisfileexceptincompliance
7. *withtheLicense.YoumayobtainacopyoftheLicenseat:
8. *
9. *http://www.apache.org/licenses/LICENSE-2.0
10. *
11. *Unlessrequiredbyapplicablelaworagreedtoinwriting,software
12. *distributedundertheLicenseisdistributedonan"ASIS"BASIS,WITHOUT
13. *WARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.Seethe
14. *Licenseforthespecificlanguagegoverningpermissionsandlimitations
15. *undertheLicense.
16. */
17. packageio.netty.example.echo;
18.
19. importio.netty.bootstrap.ServerBootstrap;
20. importio.netty.channel.ChannelFuture;
21. importio.netty.channel.ChannelInitializer;
22. importio.netty.channel.ChannelOption;
23. importio.netty.channel.EventLoopGroup;
24. importio.netty.channel.nio.NioEventLoopGroup;
25. importio.netty.channel.socket.SocketChannel;
26. importio.netty.channel.socket.nio.NioServerSocketChannel;
27. importio.netty.handler.logging.LogLevel;
28. importio.netty.handler.logging.LoggingHandler;
29.
30. /**
评论2
最新资源