{"id":1625,"date":"2025-03-22T00:44:28","date_gmt":"2025-03-21T16:44:28","guid":{"rendered":"http:\/\/codermr.com\/?p=1625"},"modified":"2025-03-22T23:44:26","modified_gmt":"2025-03-22T15:44:26","slug":"netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86","status":"publish","type":"post","link":"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/","title":{"rendered":"Netty\u6280\u672f\u70b9\u6574\u7406"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\"><strong>Netty\u662f\u4ec0\u4e48\uff1f<\/strong><\/h1>\n\n\n\n<p>1\uff09\u672c\u8d28\uff1a<strong>\u57fa\u4e8eNIO\u7684\u901a\u4fe1\u6846\u67b6<\/strong>\u505a\u7684\u4e00\u4e2a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\"><strong>Jar \u5305<\/strong><\/mark>\u3002<br>2\uff09\u76ee\u7684\uff1a<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u5feb\u901f\u5f00\u53d1<\/mark><\/strong>\u9ad8\u6027\u80fd\u3001\u9ad8\u53ef\u9760\u6027\u7684\u7f51\u7edc<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7a0b\u5e8f<\/mark><\/strong>\u3002<br>3\uff09\u4f18\u70b9\uff1a\u63d0\u4f9b\u5f02\u6b65\u7684\u3001\u4e8b\u4ef6\u9a71\u52a8\u7684\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\u548c\u5de5\u5177\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Netty\u4e3a\u4ec0\u4e48\u5e76\u53d1\u9ad8<\/strong>\uff1f<\/h1>\n\n\n\n<p>Netty \u662f\u4e00\u6b3e\u57fa\u4e8e NIO\uff08Nonblocking I\/O\uff0c\u975e\u963b\u585eIO\uff09\u5f00\u53d1\u7684\u7f51\u7edc\u901a\u4fe1\u6846\u67b6\uff0c\u5bf9\u6bd4\u4e8eBIO\uff08Blocking I\/O\uff0c\u963b\u585eIO\uff09\uff0c\u4ed6\u7684\u5e76\u53d1\u6027\u80fd\u5f97\u5230\u4e86\u5f88\u5927\u63d0\u9ad8<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Netty\u4e3a\u4ec0\u4e48\u4f20\u8f93\u5feb<\/strong>\uff1f<\/h1>\n\n\n\n<p>Netty \u7684\u4f20\u8f93\u5feb\u5176\u5b9e\u4e5f\u662f\u4f9d\u8d56\u4e86 NIO \u7684\u4e00\u4e2a\u7279\u6027\u2014\u2014<em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u96f6\u62f7\u8d1d<\/mark><\/em>\u3002\u6211\u4eec\u77e5\u9053\uff0cJava\u7684\u5185\u5b58\u6709\u5806\u5185\u5b58\u3001\u6808\u5185\u5b58\u548c\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u7b49\u7b49\uff0c\u5176\u4e2d\u5806\u5185\u5b58\u662f\u5360\u7528\u5185\u5b58\u7a7a\u95f4\u6700\u5927\u7684\u4e00\u5757\uff0c\u4e5f\u662fJava\u5bf9\u8c61\u5b58\u653e\u7684\u5730\u65b9\uff0c\u4e00\u822c\u6211\u4eec\u7684\u6570\u636e\u5982\u679c\u9700\u8981\u4eceIO\u8bfb\u53d6\u5230\u5806\u5185\u5b58\uff0c\u4e2d\u95f4\u9700\u8981\u7ecf\u8fc7Socket\u7f13\u51b2\u533a\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e00\u4e2a\u6570\u636e\u4f1a\u88ab\u62f7\u8d1d\u4e24\u6b21\u624d\u80fd\u5230\u8fbe\u4ed6\u7684\u7684\u7ec8\u70b9\uff0c\u5982\u679c\u6570\u636e\u91cf\u5927\uff0c\u5c31\u4f1a\u9020\u6210\u4e0d\u5fc5\u8981\u7684\u8d44\u6e90\u6d6a\u8d39\u3002<\/p>\n\n\n\n<p>Netty\u9488\u5bf9\u8fd9\u79cd\u60c5\u51b5\uff0c\u4f7f\u7528\u4e86NIO\u4e2d\u7684\u53e6\u4e00\u5927\u7279\u6027\u2014\u2014\u96f6\u62f7\u8d1d\uff0c\u5f53\u4ed6\u9700\u8981\u63a5\u6536\u6570\u636e\u7684\u65f6\u5019\uff0c\u4ed6\u4f1a\u5728\u5806\u5185\u5b58\u4e4b\u5916\u5f00\u8f9f\u4e00\u5757\u5185\u5b58\uff0c\u6570\u636e\u5c31\u76f4\u63a5\u4eceIO\u8bfb\u5230\u4e86\u90a3\u5757\u5185\u5b58\u4e2d\u53bb\uff0c\u5728netty\u91cc\u9762\u901a\u8fc7ByteBuf\u53ef\u4ee5\u76f4\u63a5\u5bf9\u8fd9\u4e9b\u6570\u636e\u8fdb\u884c\u76f4\u63a5\u64cd\u4f5c\uff0c\u4ece\u800c\u52a0\u5feb\u4e86\u4f20\u8f93\u901f\u5ea6\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u5148\u770b\u4e00\u4e2a Demo<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u670d\u52a1\u7aef\u4ee3\u7801<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class NettyServer {\n\n    \/\/ \u5f15\u5bfc\u7c7b\u6700\u5c0f\u5316\u7684\u53c2\u6570\u914d\u7f6e\u5c31\u662f\u4e0b\u9762\u56db\u4e2a\uff1a\u914d\u7f6e\u7ebf\u7a0b\u7ec4\u3001IO\u6a21\u578b\u3001\u5904\u7406\u903b\u8f91\u3001\u7ed1\u5b9a\u7aef\u53e3\u3002\n    public static void main(String&#91;] args) {\n        \/\/\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u7b2c\u4e00\u6b65 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n        \/\/\u2588\u2588\u2588\u2588\u6ce8\u610f\u8fd9\u91cc\u521b\u5efa\u4e86\u4e24\u4e2a NioEventLoopGroup \u5bf9\u8c61\uff0c\u5176\u4e2d bossGroup \u662f\u76d1\u542c\u5ba2\u6237\u7aef\u8bf7\u6c42\uff0c\u53e6\u4e00\u4e2a workerGroup \u662f\u5904\u7406\u5ba2\u6237\u7aef\u8bf7\u6c42\uff0c\u8fd9\u79cd\u8bbe\u8ba1\u5728\u4e2d\u95f4\u4ef6\u6280\u672f\u4e2d\u5f88\u5e38\u7528\uff0c\u6bd4\u5982 zookeeper \u4e5f\u662f\u4e00\u4e2a\u8282\u70b9\u63a5\u53d7\u8bf7\u6c42\u5e76\u8f6c\u53d1\uff0c\u5176\u4ed6\u8282\u70b9\u5904\u7406\u8bf7\u6c42\u2588\u2588\u2588\u2588\n        \/\/ bossGroup\u7684\u4f5c\u7528\u662f\u76d1\u542c\u5ba2\u6237\u7aef\u8bf7\u6c42\n        NioEventLoopGroup bossGroup = new NioEventLoopGroup();\n        \/\/ workerGroup\u7684\u4f5c\u7528\u662f\u5904\u7406\u6bcf\u6761\u8fde\u63a5\u7684\u6570\u636e\u8bfb\u5199\n        NioEventLoopGroup workerGroup = new NioEventLoopGroup();\n        \/\/\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u7b2c\u4e8c\u6b65 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n        \/\/\u2588\u2588\u2588\u2588\u521b\u5efa\u4e00\u4e2a ServerBootstrap  \u5f15\u5bfc\u7c7b\u7684\u5bf9\u8c61\u2588\u2588\u2588\u2588\n        ServerBootstrap serverBootstrap = new ServerBootstrap();\n        \/\/\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u7b2c\u4e09\u6b65 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n        serverBootstrap\n          .group(bossGroup, workerGroup) \/\/\u25883.1\u2588\u914d\u7f6e\u7b2c\u4e00\u6b65\u521b\u5efa\u7684 bossGroup \u548c workerGroup \u5bf9\u8c61\n          .channel(NioServerSocketChannel.class) \/\/\u25883.2\u2588 .channel\u662f\u914d\u7f6e\u670d\u52a1\u7aef\u7684IO\u6a21\u578b\uff0c\u4e0a\u9762\u4ee3\u7801\u914d\u7f6e\u7684\u662fNIO\u6a21\u578b\u3002\/\/ \u4e5f\u53ef\u4ee5\u914d\u7f6e\u4e3aBIO\uff0c\u5982OioServerSocketChannel.class\u3002\n          .childHandler(new ChannelInitializer&lt;NioSocketChannel&gt;() {\n              \/\/\u25883.3\u2588 .childHandler\u7528\u4e8e\u914d\u7f6e\u6bcf\u6761\u8fde\u63a5\u7684\u6570\u636e\u8bfb\u5199\u548c\u4e1a\u52a1\u903b\u8f91\u7b49\u3002\u4e00\u822c\u4f1a\u518d\u5199\u4e00\u4e2a\u5355\u72ec\u7684\u7c7b\u4e5f\u5c31\u662f\u521d\u59cb\u5316\u5668\u3002==\u300b\u4e00\u822c\u4f1a\u5728\u8fd9\u91cc\u81ea\u5b9a\u4e49\u5904\u7406\u8bfb\u5199\u7684\u903b\u8f91\uff01\uff01\uff01\n              @Override\n              protected void initChannel(NioSocketChannel ch) {\n                  System.out.println(\"============initChannel============\");\n              }\n          })\n          .handler(new ChannelInitializer&lt;NioServerSocketChannel&gt;() {\n              \/\/\u25883.4\u2588 \u7528\u4e8e\u6307\u5b9a\u670d\u52a1\u7aef\u542f\u52a8\u4e2d\u7684\u903b\u8f91\n              @Override\n              protected void initChannel(NioServerSocketChannel ch) {\n                  System.out.println(\"============\u670d\u52a1\u7aef\u542f\u52a8\u4e2d============\");\n              }\n          });\n        \/\/\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u7b2c\u56db\u6b65\uff1a\u7ed1\u5b9a\u7aef\u53e3\u53f7 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n        serverBootstrap.bind(8000);\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5ba2\u670d\u7aef\u4ee3\u7801<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class NettyClient {\n\n    public static void main(String&#91;] args) {\n        \/\/\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u7b2c\u4e00\u6b65 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n        \/\/\u2588\u2588\u914d\u7f6e\u5ba2\u6237\u7aef\u7684\u7ebf\u7a0b\u6a21\u578b\u2588\u2588\n        NioEventLoopGroup workerGroup = new NioEventLoopGroup();\n        \/\/\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u7b2c\u4e8c\u6b65 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n        \/\/\u2588\u2588\u521b\u5efa\u5f15\u5bfc\u7c7b\u5bf9\u8c61\uff08\u6ce8\u610f:\u670d\u52a1\u7aef\u662f ServerBootstrap\uff0c\u800c\u5ba2\u6237\u7aef\u662f Bootstrap\uff09\u2588\u2588\n        Bootstrap bootstrap = new Bootstrap();\n        \/\/\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 \u7b2c\u4e09\u6b65 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\n        bootstrap\n          \/\/ 1.\u6307\u5b9a\u7ebf\u7a0b\u6a21\u578b\n          .group(workerGroup)\n          \/\/ 2.\u6307\u5b9a IO \u7c7b\u578b\u4e3a NIO\n          .channel(NioSocketChannel.class)\n          \/\/ 3.IO \u5904\u7406\u903b\u8f91\n          .handler(new ChannelInitializer&lt;SocketChannel&gt;() {\n              @Override\n              public void initChannel(SocketChannel ch) {\n                  System.out.println(\"============ NettyClient: NettyClient\uff1ainitChannel ============\");\n              }\n          });\n        \/\/ 4.\u5efa\u7acb\u8fde\u63a5\n        bootstrap.connect(\"127.0.0.1\", 8000).addListener(future -&gt; {\n            if (future.isSuccess()) {\n                System.out.println(\"NettyClient\uff1a\u8fde\u63a5\u6210\u529f!\");\n            } else {\n                System.err.println(\"NettyClient\uff1a\u8fde\u63a5\u5931\u8d25!\");\n                \/\/\u91cd\u65b0\u8fde\u63a5\n            }\n        });\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u670d\u52a1\u7aef\u65e5\u5fd7\uff1a<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>============\u670d\u52a1\u7aef\u542f\u52a8\u4e2d============\n============initChannel============<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5ba2\u6237\u7aef\u65e5\u5fd7\uff1a<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>============ NettyClient: NettyClient\uff1ainitChannel ============\nNettyClient\uff1a\u8fde\u63a5\u6210\u529f!<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>\u6570\u636e\u4f20\u8f93\u7684\u8f7d\u4f53\uff1aByteBuf<\/strong><\/h1>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-26.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1736\" height=\"655\" src=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-26.png\" alt=\"\" class=\"wp-image-1630\" srcset=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-26.png 1736w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-26-300x113.png 300w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-26-1024x386.png 1024w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-26-768x290.png 768w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-26-1536x580.png 1536w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-26-1222x461.png 1222w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-26-922x348.png 922w\" sizes=\"(max-width: 1736px) 100vw, 1736px\" \/><\/a><\/figure>\n\n\n\n<ol>\n<li>ByteBuf \u662f\u4e00\u4e2a\u5b57\u8282\u5bb9\u5668\uff0c\u5bb9\u5668\u91cc\u9762\u7684\u7684\u6570\u636e\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\uff0c<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u7b2c\u4e00\u4e2a\u90e8\u5206<\/mark><\/strong>\u662f\u5df2\u7ecf\u4e22\u5f03\u7684\u5b57\u8282\uff0c\u8fd9\u90e8\u5206\u6570\u636e\u662f\u65e0\u6548\u7684\uff1b<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u7b2c\u4e8c\u90e8\u5206<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">\u662f\u53ef\u8bfb\u5b57\u8282<\/mark><\/strong>\uff0c\u8fd9\u90e8\u5206\u6570\u636e\u662f ByteBuf \u7684\u4e3b\u4f53\u6570\u636e\uff0c \u4ece ByteBuf \u91cc\u9762\u8bfb\u53d6\u7684\u6570\u636e\u90fd\u6765\u81ea\u8fd9\u4e00\u90e8\u5206; <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u7b2c\u4e09\u90e8\u5206<\/mark><\/strong>\u7684\u6570\u636e\u662f<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">\u53ef\u5199\u5b57\u8282<\/mark><\/strong>\uff0c\u6240\u6709\u5199\u5230 ByteBuf \u7684\u6570\u636e\u90fd\u4f1a\u5199\u5230\u8fd9\u4e00\u6bb5\u3002<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u6700\u540e\u4e00\u90e8\u5206\u865a\u7ebf\u8868\u793a\u7684\u662f\u8be5 ByteBuf \u6700\u591a\u8fd8\u80fd\u6269\u5bb9\u591a\u5c11\u5bb9\u91cf\u3002<\/mark><\/li>\n\n\n\n<li>\u4ee5\u4e0a\u4e09\u6bb5\u5185\u5bb9\u662f\u88ab\u4e24\u4e2a\u6307\u9488\u7ed9\u5212\u5206\u51fa\u6765\u7684\uff0c\u4ece\u5de6\u5230\u53f3\uff0c\u4f9d\u6b21\u662f<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\"><strong>\u8bfb\u6307\u9488<\/strong><\/mark>\uff08readerIndex\uff09\u3001<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u5199\u6307\u9488<\/mark><\/strong>\uff08writerIndex\uff09\uff0c\u7136\u540e<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u8fd8\u6709\u4e00\u4e2a\u53d8\u91cf capacity\uff0c\u8868\u793a ByteBuf \u5e95\u5c42\u5185\u5b58\u7684\u603b\u5bb9\u91cf<\/mark><\/strong>\u3002<\/li>\n\n\n\n<li>\u4ece ByteBuf \u4e2d\u6bcf\u8bfb\u53d6\u4e00\u4e2a\u5b57\u8282\uff0creaderIndex \u81ea\u589e1\uff0cByteBuf \u91cc\u9762\u603b\u5171\u6709 writerIndex-readerIndex \u4e2a\u5b57\u8282\u53ef\u8bfb, \u7531\u6b64\u53ef\u4ee5\u63a8\u8bba\u51fa\u5f53 readerIndex \u4e0e writerIndex \u76f8\u7b49\u7684\u65f6\u5019\uff0cByteBuf \u4e0d\u53ef\u8bfb\u3002<\/li>\n\n\n\n<li>\u5199\u6570\u636e\u662f\u4ece writerIndex \u6307\u5411\u7684\u90e8\u5206\u5f00\u59cb\u5199\uff0c\u6bcf\u5199\u4e00\u4e2a\u5b57\u8282\uff0cwriterIndex \u81ea\u589e1\uff0c\u76f4\u5230\u589e\u5230 capacity\uff0c\u8fd9\u4e2a\u65f6\u5019\uff0c\u8868\u793a ByteBuf \u5df2\u7ecf\u4e0d\u53ef\u5199\u4e86\u3002<\/li>\n\n\n\n<li>ByteBuf \u91cc\u9762\u5176\u5b9e\u8fd8\u6709\u4e00\u4e2a\u53c2\u6570 maxCapacity\uff0c\u5f53\u5411 ByteBuf \u5199\u6570\u636e\u7684\u65f6\u5019\uff0c\u5982\u679c\u5bb9\u91cf\u4e0d\u8db3\uff0c\u90a3\u4e48\u8fd9\u4e2a\u65f6\u5019\u53ef\u4ee5\u8fdb\u884c\u6269\u5bb9\uff0c\u76f4\u5230 capacity \u6269\u5bb9\u5230 maxCapacity\uff0c\u8d85\u8fc7 maxCapacity \u5c31\u4f1a\u62a5\u9519\u3002<\/li>\n<\/ol>\n\n\n\n<h1 class=\"wp-block-heading\">Demo \u81ea\u5b9a\u4e49\u5904\u7406\u903b\u8f91<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u670d\u52a1\u7aef<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class NettyServer {\n\n    public static void main(String&#91;] args) {\n        \/\/ \u4e24\u4e2aNioEventLoopGroup\u5bf9\u8c61\uff0c\u53ef\u4ee5\u770b\u4f5c\u4e24\u4e2a\u7ebf\u7a0b\u7ec4\u3002bossGroup\u7684\u4f5c\u7528\u662f\u76d1\u542c\u5ba2\u6237\u7aef\u8bf7\u6c42\u3002workerGroup\u7684\u4f5c\u7528\u662f\u5904\u7406\u6bcf\u6761\u8fde\u63a5\u7684\u6570\u636e\u8bfb\u5199\u3002\n        NioEventLoopGroup bossGroup = new NioEventLoopGroup();\n        NioEventLoopGroup workerGroup = new NioEventLoopGroup();\n\n        \/\/ ServerBootstrap\u662f\u4e00\u4e2a\u5f15\u5bfc\u7c7b\uff0c\u5176\u5bf9\u8c61\u7684\u4f5c\u7528\u662f\u5f15\u5bfc\u670d\u52a1\u5668\u7684\u542f\u52a8\u5de5\u4f5c\n        ServerBootstrap serverBootstrap = new ServerBootstrap();\n        serverBootstrap\n            \/\/ .group\u662f\u914d\u7f6e\u4e0a\u9762\u4e24\u4e2a\u7ebf\u7a0b\u7ec4\u7684\u89d2\u8272\uff0c\u4e5f\u5c31\u662f\u8c01\u53bb\u76d1\u542c\u3001\u8c01\u53bb\u5904\u7406\u8bfb\u5199\u3002\u4e0a\u9762\u53ea\u662f\u521b\u5efa\u4e86\u4e24\u4e2a\u7ebf\u7a0b\u7ec4\uff0c\u5e76\u6ca1\u6709\u5b9e\u9645\u4f7f\u7528\n            .group(bossGroup, workerGroup)\n            \/\/ .channel\u662f\u914d\u7f6e\u670d\u52a1\u7aef\u7684IO\u6a21\u578b\uff0c\u4e0a\u9762\u4ee3\u7801\u914d\u7f6e\u7684\u662fNIO\u6a21\u578b\u3002\u4e5f\u53ef\u4ee5\u914d\u7f6e\u4e3aBIO\uff0c\u5982OioServerSocketChannel.class\n            .channel(NioServerSocketChannel.class)\n            \/\/ .childHandler\u7528\u4e8e\u914d\u7f6e\u6bcf\u6761\u8fde\u63a5\u7684\u6570\u636e\u8bfb\u5199\u548c\u4e1a\u52a1\u903b\u8f91\u7b49\u3002\u5b9e\u9645\u4f7f\u7528\u4e2d\u4e3a\u4e86\u89c4\u8303\u8d77\u89c1\uff0c\n            \/\/ \u4f1a\u5355\u72ec\u5199\u4e00\u4e2a\u7c7b\u4e5f\u5c31\u662f\u521d\u59cb\u5316\u5668\uff0c\u5728\u91cc\u9762\u5199\u4e0a\u9700\u8981\u7684\u64cd\u4f5c\u3002\u5c31\u5982Netty\u5b9e\u6218\u90a3\u7bc7\u4e2d\u7684\u4ee3\u7801\u4e00\u6837\u3002\n            .childHandler(new ChannelInitializer&lt;NioSocketChannel&gt;() {\n                @Override\n                protected void initChannel(NioSocketChannel ch) {\n                    ch.pipeline().addLast(new FirstServerHandler());\n                    System.out.println(\"============initChannel============\");\n                }\n            })\n            \/\/ handler()\u65b9\u6cd5\uff1a\u4e0a\u9762\u7684childHandler\u662f\u5904\u7406\u8fde\u63a5\u7684\u8bfb\u5199\u903b\u8f91\uff0c\u8fd9\u4e2a\u662f\u7528\u4e8e\u6307\u5b9a\u670d\u52a1\u7aef\u542f\u52a8\u4e2d\u7684\u903b\u8f91.\n            .handler(new ChannelInitializer&lt;NioServerSocketChannel&gt;() {\n                @Override\n                protected void initChannel(NioServerSocketChannel ch) {\n                    System.out.println(\"============\u670d\u52a1\u7aef\u542f\u52a8\u4e2d============\");\n                }\n            });\n\n        serverBootstrap.bind(8000);\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u81ea\u5b9a\u4e49\u5904\u7406\u5668<\/mark><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n Desc: \u670d\u52a1\u5668\u4f1a\u54cd\u5e94\u4f20\u5165\u8fdb\u6765\u7684\u6d88\u606f\uff0c\u6240\u4ee5\u5b83\u9700\u8981\u5b9e\u73b0 ChannelInboundHandler \u63a5\u53e3\uff0c\u7528\u6765\u5b9a\u4e49\u54cd\u5e94\"\u5165\u7ad9\"\u4e8b\u4ef6\u7684\u65b9\u6cd5\u3002\n \u53ef\u4ee5\u4f7f\u7528 ChannelInboundHandlerAdapter \u5373\u53ef\uff0c\u5b83\u5df2\u5b9e\u73b0\u4e86ChannelInboundHandler\u63a5\u53e3\u63a5\u53e3\u5e76\u63d0\u4f9b\u4e86 ChannelInboundHandler \u7684\u9ed8\u8ba4\u5b9e\u73b0\u3002\n &lt;p&gt;\n *\n * @author zhouxingbin\n * @date 2020\/12\/24\n *\/\npublic class FirstServerHandler extends ChannelInboundHandlerAdapter {\n\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) {\n        ByteBuf byteBuf = (ByteBuf) msg;\n        System.out.println(new Date() + \": \u670d\u52a1\u7aef\u8bfb\u5230\u6570\u636e -&gt; \" + byteBuf.toString(Charset.forName(\"utf-8\")));\n        \/\/\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u7684\u6d88\u606f\u540e\u6211\u4eec\u518d\u56de\u590d\u5ba2\u6237\u7aef\n        ByteBuf out = getByteBuf(ctx);\n        ctx.channel().writeAndFlush(out);\n    }\n\n    private ByteBuf getByteBuf(ChannelHandlerContext ctx) {\n        byte&#91;] bytes = \"\u3010\u670d\u52a1\u5668\u3011:\u6211\u662f\u670d\u52a1\u5668\uff0c\u6211\u6536\u5230\u4f60\u7684\u6d88\u606f\u4e86\uff01\".getBytes(Charset.forName(\"utf-8\"));\n        ByteBuf buffer = ctx.alloc().buffer();\n        buffer.writeBytes(bytes);\n        return buffer;\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5ba2\u6237\u7aef<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class NettyClient {\n\n    public static void main(String&#91;] args) {\n        NioEventLoopGroup workerGroup = new NioEventLoopGroup();\n        Bootstrap bootstrap = new Bootstrap();\n        bootstrap\n          \/\/ 1.\u6307\u5b9a\u7ebf\u7a0b\u6a21\u578b\n          .group(workerGroup)\n          \/\/ 2.\u6307\u5b9a IO \u7c7b\u578b\u4e3a NIO\n          .channel(NioSocketChannel.class)\n          \/\/ 3.IO \u5904\u7406\u903b\u8f91\n          .handler(new ChannelInitializer&lt;SocketChannel&gt;() {\n              @Override\n              public void initChannel(SocketChannel ch) {\n                  System.out.println(\"============ NettyClient\uff1ainitChannel ============\");\n                  ch.pipeline().addLast(new FirstClientHandler());\n              }\n          });\n        \/\/ 4.\u5efa\u7acb\u8fde\u63a5\n        bootstrap.connect(\"127.0.0.1\", 8000).addListener(future -&gt; {\n            if (future.isSuccess()) {\n                System.out.println(\"NettyClient\uff1a\u8fde\u63a5\u6210\u529f!\");\n            } else {\n                System.err.println(\"NettyClient\uff1a\u8fde\u63a5\u5931\u8d25!\");\n                \/\/\u91cd\u65b0\u8fde\u63a5\n            }\n        });\n    }\n}<\/code><\/pre>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u81ea\u5b9a\u4e49\u5904\u7406\u5668<\/mark><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class FirstClientHandler extends ChannelInboundHandlerAdapter {\n\n    \/\/ channelActive()\u65b9\u6cd5\u4f1a\u5728\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u5efa\u7acb\u8fde\u63a5\u540e\u8c03\u7528\u3002\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5728\u8fd9\u91cc\u9762\u7f16\u5199\u903b\u8f91\u4ee3\u7801\n    @Override\n    public void channelActive(ChannelHandlerContext ctx) {\n        System.out.println(\"\u5ba2\u6237\u7aef\u53d1\u9001\u6d88\u606f...\");\n        \/\/ 1. \u83b7\u53d6\u6570\u636e\n        ByteBuf buffer = getByteBuf(ctx);\n        \/\/ 2. \u5199\u6570\u636e\uff08\u5f80\u670d\u52a1\u7aef\u53d1\u9001\u6570\u636e\uff09\n        ctx.channel().writeAndFlush(buffer);\n    }\n\n    private ByteBuf getByteBuf(ChannelHandlerContext ctx) {\n        \/\/ 1. \u83b7\u53d6\u4e8c\u8fdb\u5236\u62bd\u8c61 ByteBuf \u3010.alloc().buffer()\u7684\u4f5c\u7528\u662f\u628a\u5b57\u7b26\u4e32\u7684\u4e8c\u8fdb\u5236\u6570\u636e\u586b\u5145\u5230ByteBuf\u3011\n        ByteBuf buffer = ctx.alloc().buffer();\n        \/\/ 2. \u51c6\u5907\u6570\u636e\uff0c\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u96c6\u4e3a utf-8\n        byte&#91;] bytes = (\"\u3010\u5ba2\u6237\u7aef\u3011:\u8fd9\u662f\u5ba2\u6237\u7aef\u53d1\u9001\u7684\u6d88\u606f\uff1a\" + new Date()).getBytes(Charset.forName(\"utf-8\"));\n        \/\/ 3. \u586b\u5145\u6570\u636e\u5230 ByteBuf \u3010.writeBytes()\u7684\u4f5c\u7528\u662f\u628a\u6570\u636e\u5199\u5230\u670d\u52a1\u5668\u3011\n        buffer.writeBytes(bytes);\n        return buffer;\n    }\n\n    \/\/ channelRead()\u5728\u63a5\u53d7\u5230\u670d\u52a1\u7aef\u7684\u6d88\u606f\u540e\u8c03\u7528\uff08\u4ece\u670d\u52a1\u7aef\u63a5\u6536\u6570\u636e\uff09\n    @Override\n    public void channelRead(ChannelHandlerContext ctx, Object msg) {\n        ByteBuf byteBuf = (ByteBuf) msg;\n        \/\/\u63a5\u6536\u670d\u52a1\u7aef\u7684\u6d88\u606f\u5e76\u6253\u5370\n        System.out.println(byteBuf.toString(Charset.forName(\"utf-8\")));\n    }\n\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>pipeline\u4e0echannelHandler<\/strong><\/h1>\n\n\n\n<p>\u3000\u3000\u901a\u8fc7\u4e0a\u9762\u7684\u4e00\u4e9b\u5b9e\u6218\uff0c\u53ef\u4ee5\u53d1\u73b0\u6211\u4eec\u6240\u6709\u7684\u903b\u8f91\u4ee3\u7801\u90fd\u5199\u5728\u4e86\u4e00\u4e2aHandler\u7c7b\u91cc\u9762\uff0c\u5e78\u597d\u73b0\u5728\u9700\u8981\u5904\u7406\u7684\u4e1a\u52a1\u4e0d\u662f\u5f88\u591a\u3002\u5982\u679c\u4ee5\u540e\u529f\u80fd\u62d3\u5c55\uff0c\u8fd9\u4e2a\u7c7b\u4f1a\u53d8\u5f97\u975e\u5e38\u81c3\u80bf\u3002Netty\u4e2d\u7684pipeline\u548cchannelHandler\u5c31\u662f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\uff0c\u5b83\u4eec\u901a\u8fc7\u8d23\u4efb\u94fe\u8bbe\u8ba1\u6a21\u5f0f\u6765\u7ec4\u7ec7\u4ee3\u7801\u903b\u8f91\uff0c\u5e76\u4e14\u80fd\u591f\u652f\u6301\u903b\u8f91\u7684\u6dfb\u52a0\u548c\u5220\u9664\uff0c\u80fd\u591f\u652f\u6301\u5404\u7c7b\u534f\u8bae\u62d3\u5c55\uff0c\u5982HTTP\u3001Websocket\u7b49\u3002\u53ef\u4ee5\u770b\u770bNetty\u5b9e\u6218\u535a\u5ba2\u4e2d\u7684\u521d\u59cb\u5316\u5668\u7c7b\uff0c\u91cc\u9762\u5c31\u662f\u901a\u8fc7pipeline\u6dfb\u52a0\u4e86\u5404\u7c7b\u534f\u8bae\u548c\u4e00\u4e9b\u903b\u8f91\u4ee3\u7801\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>pipeline\u4e0echannelHandler\u7684\u6784\u6210<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-27.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1755\" height=\"446\" src=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-27.png\" alt=\"\" class=\"wp-image-1633\" srcset=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-27.png 1755w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-27-300x76.png 300w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-27-1024x260.png 1024w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-27-768x195.png 768w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-27-1536x390.png 1536w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-27-1222x311.png 1222w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-27-922x234.png 922w\" sizes=\"(max-width: 1755px) 100vw, 1755px\" \/><\/a><\/figure>\n\n\n\n<p>\u6211\u4eec\u77e5\u9053\u4e00\u4e2a\u8fde\u63a5\u5bf9\u5e94\u4e00\u4e2achannel\uff0c\u8fd9\u4e2achannel\u7684\u6240\u6709\u5904\u7406\u903b\u8f91\u5728\u4e00\u4e2aChannelPipeline\u5bf9\u8c61\u91cc\uff0c\u5c31\u662f\u4e0a\u56fe\u4e2d\u7684pipeline\uff0c\u8fd9\u662f\u5b83\u7684\u5bf9\u8c61\u540d\u3002\u7136\u540e\u8fd9\u4e2a\u5bf9\u8c61\u91cc\u9762\u662f\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\u7ed3\u6784\uff0c\u6bcf\u4e2a\u8282\u70b9\u662f\u4e00\u4e2aChannelHandlerContext\u5bf9\u8c61\u3002\u8fd9\u4e2a\u5bf9\u8c61\u80fd\u62ff\u5230\u4e0echannel\u76f8\u5173\u7684\u6240\u6709\u4e0a\u4e0b\u6587\u4fe1\u606f\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u8fd8\u5305\u542b\u4e00\u4e2a\u91cd\u8981\u7684\u5bf9\u8c61\uff1aChannelHandler\uff0c\u5b83\u7684\u5206\u7c7b\u5982\u4e0b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-28.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1350\" height=\"473\" src=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-28.png\" alt=\"\" class=\"wp-image-1634\" srcset=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-28.png 1350w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-28-300x105.png 300w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-28-1024x359.png 1024w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-28-768x269.png 768w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-28-1222x428.png 1222w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-28-922x323.png 922w\" sizes=\"(max-width: 1350px) 100vw, 1350px\" \/><\/a><\/figure>\n\n\n\n<p>\u7b80\u5355\u5730\u8bf4\uff0c\u5b83\u5305\u542b\u4e24\u4e2a\u63a5\u53e3\u548c\u8fd9\u4e24\u4e2a\u63a5\u53e3\u7684\u5b9e\u73b0\u7c7b\uff0c\u56fe\u4e2d\u5de6\u8fb9\u7684\u5b9e\u73b0\u7c7b\u662f\u4e0d\u662f\u5f88\u719f\u6089\uff0c\u5c31\u662f\u6211\u4eec\u81ea\u5df1\u5199\u7684\u903b\u8f91\u5904\u7406\u5668\u91cc\u7684\u7ee7\u627f\u7684\u7c7b\u3002\u4ece\u540d\u5b57\u5c31\u53ef\u4ee5\u770b\u51fa\uff0c\u5b83\u4eec\u7684\u4f5c\u7528\u5206\u522b\u662f\u8bfb\u6570\u636e\u548c\u5199\u6570\u636e\uff0c\u6216\u7406\u89e3\u4e3a\u5165\u7ad9\u548c\u51fa\u6218\u3002\u6700\u91cd\u8981\u7684\u4e24\u4e2a\u65b9\u6cd5\u5206\u522b\u4e3achannelRead()\uff1a\u6d88\u606f\u5165\u7ad9\u3002\u548cwrite()\uff1a\u6d88\u606f\u51fa\u6218\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\">\u53c2\u5370\u8c61\u7b14\u8bb0\uff1a<a href=\"https:\/\/app.yinxiang.com\/shard\/s1\/nl\/3692626\/3da68613-b00a-42d6-86c8-92f729008684\">\u2588\u2588\u3010\u597d\u554a\u3011Netty\u5165\u95e8\u4e0e\u5b9e\u6218\u6559\u7a0b<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Netty \u5728 xxl-job \u4e2d\u7684\u4f7f\u7528<\/h1>\n\n\n\n<p>xxl-job \u4e2d\u7684\u6267\u884c\u5668\u4f1a\u521b\u5efa\u4e00\u4e2a netty server \u6765\u63a5\u6536\u8c03\u5ea6\u4e2d\u5fc3\u7684 http &#8220;\u8c03\u5ea6\u8bf7\u6c42&#8221;\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-47.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1081\" height=\"850\" src=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-47.png\" alt=\"\" class=\"wp-image-1665\" srcset=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-47.png 1081w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-47-300x236.png 300w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-47-1024x805.png 1024w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-47-768x604.png 768w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-47-922x725.png 922w\" sizes=\"(max-width: 1081px) 100vw, 1081px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-48.png\"><img loading=\"lazy\" decoding=\"async\" width=\"904\" height=\"700\" src=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-48.png\" alt=\"\" class=\"wp-image-1666\" srcset=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-48.png 904w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-48-300x232.png 300w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-48-768x595.png 768w\" sizes=\"(max-width: 904px) 100vw, 904px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Netty\u662f\u4ec0\u4e48\uff1f 1\uff09\u672c\u8d28\uff1a\u57fa\u4e8eNIO\u7684\u901a\u4fe1\u6846\u67b6\u505a\u7684\u4e00\u4e2a Jar \u5305\u30022\uff09\u76ee\u7684\uff1a\u5feb\u901f\u5f00\u53d1\u9ad8\u6027\u80fd\u3001\u9ad8\u53ef\u9760\u6027\u7684\u7f51&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1626,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[69],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Netty\u6280\u672f\u70b9\u6574\u7406 - \u7801\u5148\u751f\u7684\u535a\u5ba2<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty\u6280\u672f\u70b9\u6574\u7406\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Netty\u6280\u672f\u70b9\u6574\u7406 - \u7801\u5148\u751f\u7684\u535a\u5ba2\" \/>\n<meta property=\"og:description\" content=\"Netty\u662f\u4ec0\u4e48\uff1f 1\uff09\u672c\u8d28\uff1a\u57fa\u4e8eNIO\u7684\u901a\u4fe1\u6846\u67b6\u505a\u7684\u4e00\u4e2a Jar \u5305\u30022\uff09\u76ee\u7684\uff1a\u5feb\u901f\u5f00\u53d1\u9ad8\u6027\u80fd\u3001\u9ad8\u53ef\u9760\u6027\u7684\u7f51...\" \/>\n<meta property=\"og:url\" content=\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty\u6280\u672f\u70b9\u6574\u7406\/\" \/>\n<meta property=\"og:site_name\" content=\"\u7801\u5148\u751f\u7684\u535a\u5ba2\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-21T16:44:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-22T15:44:26+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/netty2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"320\" \/>\n\t<meta property=\"og:image:height\" content=\"312\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"\u7801\u5148\u751f\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/mrcode2021\" \/>\n<meta name=\"twitter:site\" content=\"@mrcode2021\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u7801\u5148\u751f\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/\"},\"author\":{\"name\":\"\u7801\u5148\u751f\",\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf\"},\"headline\":\"Netty\u6280\u672f\u70b9\u6574\u7406\",\"datePublished\":\"2025-03-21T16:44:28+00:00\",\"dateModified\":\"2025-03-22T15:44:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/\"},\"wordCount\":85,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf\"},\"keywords\":[\"netty\"],\"articleSection\":[\"JAVA\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/\",\"url\":\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/\",\"name\":\"Netty\u6280\u672f\u70b9\u6574\u7406 - \u7801\u5148\u751f\u7684\u535a\u5ba2\",\"isPartOf\":{\"@id\":\"http:\/\/codermr.com\/#website\"},\"datePublished\":\"2025-03-21T16:44:28+00:00\",\"dateModified\":\"2025-03-22T15:44:26+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"http:\/\/codermr.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Netty\u6280\u672f\u70b9\u6574\u7406\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/codermr.com\/#website\",\"url\":\"http:\/\/codermr.com\/\",\"name\":\"\u7801\u5148\u751f\u7684\u535a\u5ba2\",\"description\":\"\u6b22 \u8fce \u4e0b \u8f7d \u6211 \u5f00 \u53d1 \u7684 \u5404 \u7aef \u8f6f \u4ef6 \u548c APP\",\"publisher\":{\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/codermr.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf\",\"name\":\"\u7801\u5148\u751f\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/codermr.com\/wp-content\/uploads\/2023\/02\/wukong.jpg\",\"contentUrl\":\"http:\/\/codermr.com\/wp-content\/uploads\/2023\/02\/wukong.jpg\",\"width\":400,\"height\":400,\"caption\":\"\u7801\u5148\u751f\"},\"logo\":{\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/codermr.com\",\"https:\/\/twitter.com\/https:\/\/twitter.com\/mrcode2021\"],\"url\":\"http:\/\/codermr.com\/index.php\/author\/coderma\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Netty\u6280\u672f\u70b9\u6574\u7406 - \u7801\u5148\u751f\u7684\u535a\u5ba2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty\u6280\u672f\u70b9\u6574\u7406\/","og_locale":"zh_CN","og_type":"article","og_title":"Netty\u6280\u672f\u70b9\u6574\u7406 - \u7801\u5148\u751f\u7684\u535a\u5ba2","og_description":"Netty\u662f\u4ec0\u4e48\uff1f 1\uff09\u672c\u8d28\uff1a\u57fa\u4e8eNIO\u7684\u901a\u4fe1\u6846\u67b6\u505a\u7684\u4e00\u4e2a Jar \u5305\u30022\uff09\u76ee\u7684\uff1a\u5feb\u901f\u5f00\u53d1\u9ad8\u6027\u80fd\u3001\u9ad8\u53ef\u9760\u6027\u7684\u7f51...","og_url":"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty\u6280\u672f\u70b9\u6574\u7406\/","og_site_name":"\u7801\u5148\u751f\u7684\u535a\u5ba2","article_published_time":"2025-03-21T16:44:28+00:00","article_modified_time":"2025-03-22T15:44:26+00:00","og_image":[{"width":320,"height":312,"url":"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/netty2.png","type":"image\/png"}],"author":"\u7801\u5148\u751f","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/mrcode2021","twitter_site":"@mrcode2021","twitter_misc":{"\u4f5c\u8005":"\u7801\u5148\u751f","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/#article","isPartOf":{"@id":"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/"},"author":{"name":"\u7801\u5148\u751f","@id":"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf"},"headline":"Netty\u6280\u672f\u70b9\u6574\u7406","datePublished":"2025-03-21T16:44:28+00:00","dateModified":"2025-03-22T15:44:26+00:00","mainEntityOfPage":{"@id":"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/"},"wordCount":85,"commentCount":0,"publisher":{"@id":"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf"},"keywords":["netty"],"articleSection":["JAVA"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/","url":"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/","name":"Netty\u6280\u672f\u70b9\u6574\u7406 - \u7801\u5148\u751f\u7684\u535a\u5ba2","isPartOf":{"@id":"http:\/\/codermr.com\/#website"},"datePublished":"2025-03-21T16:44:28+00:00","dateModified":"2025-03-22T15:44:26+00:00","breadcrumb":{"@id":"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/codermr.com\/index.php\/2025\/03\/22\/netty%e6%8a%80%e6%9c%af%e7%82%b9%e6%95%b4%e7%90%86\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/codermr.com\/"},{"@type":"ListItem","position":2,"name":"Netty\u6280\u672f\u70b9\u6574\u7406"}]},{"@type":"WebSite","@id":"http:\/\/codermr.com\/#website","url":"http:\/\/codermr.com\/","name":"\u7801\u5148\u751f\u7684\u535a\u5ba2","description":"\u6b22 \u8fce \u4e0b \u8f7d \u6211 \u5f00 \u53d1 \u7684 \u5404 \u7aef \u8f6f \u4ef6 \u548c APP","publisher":{"@id":"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/codermr.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf","name":"\u7801\u5148\u751f","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"http:\/\/codermr.com\/#\/schema\/person\/image\/","url":"http:\/\/codermr.com\/wp-content\/uploads\/2023\/02\/wukong.jpg","contentUrl":"http:\/\/codermr.com\/wp-content\/uploads\/2023\/02\/wukong.jpg","width":400,"height":400,"caption":"\u7801\u5148\u751f"},"logo":{"@id":"http:\/\/codermr.com\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/codermr.com","https:\/\/twitter.com\/https:\/\/twitter.com\/mrcode2021"],"url":"http:\/\/codermr.com\/index.php\/author\/coderma\/"}]}},"_links":{"self":[{"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/posts\/1625"}],"collection":[{"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/comments?post=1625"}],"version-history":[{"count":7,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/posts\/1625\/revisions"}],"predecessor-version":[{"id":1667,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/posts\/1625\/revisions\/1667"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/media\/1626"}],"wp:attachment":[{"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/media?parent=1625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/categories?post=1625"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/tags?post=1625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}