{"id":45221,"date":"2025-06-23T07:16:15","date_gmt":"2025-06-22T23:16:15","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/45221.html"},"modified":"2025-06-23T07:16:15","modified_gmt":"2025-06-22T23:16:15","slug":"%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e7%ae%80%e4%bb%8b%e4%b8%8enetty%e5%ae%9e%e6%88%98%ef%bc%9a%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e9%ab%98%e6%80%a7%e8%83%bdecho%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/45221.html","title":{"rendered":"\u7f51\u7edc\u7f16\u7a0b\u7b80\u4ecb\u4e0eNetty\u5b9e\u6218\uff1a\u4ece\u5165\u95e8\u5230\u9ad8\u6027\u80fdEcho\u670d\u52a1\u5668"},"content":{"rendered":"<h4>\u7f51\u7edc\u7f16\u7a0b\u7b80\u4ecb\u4e0eNetty\u5b9e\u6218&#xff1a;\u4ece\u5165\u95e8\u5230\u9ad8\u6027\u80fdEcho\u670d\u52a1\u5668<\/h4>\n<hr \/>\n<h5>\u4e00\u3001\u7f51\u7edc\u7f16\u7a0b\u57fa\u7840<\/h5>\n<h6>1.1 \u4ec0\u4e48\u662f\u7f51\u7edc\u7f16\u7a0b&#xff1f;<\/h6>\n<p>\u7f51\u7edc\u7f16\u7a0b\u662f\u6307\u901a\u8fc7\u200b\u200b\u7f51\u7edc\u534f\u8bae&#xff08;\u5982TCP\/IP&#xff09;\u200b\u200b\u5b9e\u73b0\u4e0d\u540c\u8bbe\u5907\u95f4\u6570\u636e\u901a\u4fe1\u7684\u6280\u672f\u3002\u6838\u5fc3\u76ee\u6807\u662f\u8ba9\u7a0b\u5e8f\u80fd\u591f\u901a\u8fc7\u7f51\u7edc\u4e0e\u5176\u4ed6\u7a0b\u5e8f\u4ea4\u6362\u6570\u636e&#xff0c;\u4f8b\u5982\u7f51\u9875\u6d4f\u89c8\u3001\u5373\u65f6\u901a\u8baf\u3001\u6587\u4ef6\u4f20\u8f93\u7b49\u573a\u666f\u5747\u4f9d\u8d56\u7f51\u7edc\u7f16\u7a0b\u3002<\/p>\n<h6>1.2 \u4f20\u7edf\u7f51\u7edc\u7f16\u7a0b\u7684\u75db\u70b9&#xff08;BIO\u6a21\u578b&#xff09;<\/h6>\n<p>\u65e9\u671f\u7f51\u7edc\u7f16\u7a0b\u591a\u57fa\u4e8e\u200b\u200bBIO&#xff08;\u540c\u6b65\u963b\u585eIO&#xff09;\u200b\u200b&#xff0c;\u5176\u6838\u5fc3\u903b\u8f91\u662f&#xff1a;<\/p>\n<ul>\n<li>\u670d\u52a1\u7aef\u4e3a\u6bcf\u4e2a\u5ba2\u6237\u7aef\u8fde\u63a5\u521b\u5efa\u4e00\u4e2a\u72ec\u7acb\u7ebf\u7a0b\u5904\u7406\u8bf7\u6c42\u3002<\/li>\n<li>\u5f53\u5e76\u53d1\u91cf\u9ad8\u65f6&#xff08;\u59821000&#043;\u8fde\u63a5&#xff09;&#xff0c;\u7ebf\u7a0b\u8d44\u6e90\u4f1a\u88ab\u8017\u5c3d&#xff0c;\u5bfc\u81f4\u6027\u80fd\u9aa4\u964d\u3002<\/li>\n<\/ul>\n<p>\u200b\u200b\u95ee\u9898\u603b\u7ed3\u200b\u200b&#xff1a;\u7ebf\u7a0b\u8d44\u6e90\u6602\u8d35\u3001\u6269\u5c55\u6027\u5dee\u3001\u8d44\u6e90\u5229\u7528\u7387\u4f4e\u3002<\/p>\n<h6>1.3 \u7f51\u7edc\u534f\u8bae\u57fa\u7840<\/h6>\n<p>\u7f51\u7edc\u901a\u4fe1\u9700\u9075\u5faa\u5206\u5c42\u534f\u8bae&#xff0c;\u6700\u5e38\u7528\u7684\u662f\u200b\u200bTCP\/IP\u6a21\u578b\u200b\u200b&#xff1a;<\/p>\n<ul>\n<li>\u200b\u200b\u5e94\u7528\u5c42\u200b\u200b&#xff08;\u5982HTTP\u3001WebSocket&#xff09;&#xff1a;\u5b9a\u4e49\u6570\u636e\u683c\u5f0f\u548c\u4ea4\u4e92\u89c4\u5219\u3002<\/li>\n<li>\u200b\u200b\u4f20\u8f93\u5c42\u200b\u200b&#xff08;\u5982TCP\u3001UDP&#xff09;&#xff1a;\u4fdd\u8bc1\u6570\u636e\u53ef\u9760\u4f20\u8f93&#xff08;TCP&#xff09;\u6216\u9ad8\u6548\u4f20\u8f93&#xff08;UDP&#xff09;\u3002<\/li>\n<li>\u200b\u200b\u7f51\u7edc\u5c42\u200b\u200b&#xff08;IP&#xff09;&#xff1a;\u8d1f\u8d23\u5730\u5740\u5bfb\u5740\u548c\u8def\u7531\u3002<\/li>\n<li>\u200b\u200b\u94fe\u8def\u5c42\u200b\u200b&#xff08;\u5982\u4ee5\u592a\u7f51&#xff09;&#xff1a;\u5904\u7406\u7269\u7406\u8bbe\u5907\u901a\u4fe1\u3002<\/li>\n<\/ul>\n<h5>\u4e8c\u3001Netty&#xff1a;\u9ad8\u6027\u80fd\u7f51\u7edc\u7f16\u7a0b\u6846\u67b6<\/h5>\n<h6>2.1 Netty\u662f\u4ec0\u4e48&#xff1f;<\/h6>\n<p>Netty\u662f\u7531JBOSS\u63d0\u4f9b\u7684\u200b\u200b\u5f02\u6b65\u4e8b\u4ef6\u9a71\u52a8\u7684\u7f51\u7edc\u5e94\u7528\u6846\u67b6\u200b\u200b&#xff0c;\u57fa\u4e8eJava NIO\u5b9e\u73b0&#xff0c;\u4e13\u4e3a\u89e3\u51b3\u9ad8\u5e76\u53d1\u3001\u4f4e\u5ef6\u8fdf\u7f51\u7edc\u901a\u4fe1\u95ee\u9898\u8bbe\u8ba1\u3002\u5b83\u7b80\u5316\u4e86NIO\u7684\u590d\u6742\u64cd\u4f5c&#xff08;\u5982\u7ebf\u7a0b\u7ba1\u7406\u3001\u7f13\u51b2\u533a\u5904\u7406&#xff09;&#xff0c;\u63d0\u4f9b\u4e86\u9ad8\u6027\u80fd\u3001\u53ef\u6269\u5c55\u7684\u7f51\u7edc\u7f16\u7a0b\u80fd\u529b\u3002<\/p>\n<h6>2.2 Netty\u6838\u5fc3\u7ec4\u4ef6<\/h6>\n<ul>\n<li>\u200b\u200bChannel\u200b\u200b&#xff1a;\u7f51\u7edc\u901a\u4fe1\u7684\u62bd\u8c61&#xff08;\u7c7b\u4f3cSocket&#xff09;&#xff0c;\u652f\u6301\u8bfb\u5199\u64cd\u4f5c\u3002<\/li>\n<li>\u200b\u200bEventLoop\u200b\u200b&#xff1a;\u4e8b\u4ef6\u5faa\u73af&#xff08;\u5355\u7ebf\u7a0b\u6216\u591a\u7ebf\u7a0b&#xff09;&#xff0c;\u8d1f\u8d23\u76d1\u542c\u548c\u5904\u7406IO\u4e8b\u4ef6\u3002<\/li>\n<li>\u200b\u200bChannelPipeline\u200b\u200b&#xff1a;\u5904\u7406\u5668\u94fe&#xff0c;\u6309\u987a\u5e8f\u6267\u884c\u5165\u7ad9&#xff08;Inbound&#xff09;\u548c\u51fa\u7ad9&#xff08;Outbound&#xff09;\u5904\u7406\u5668\u3002<\/li>\n<li>\u200b\u200bHandler\u200b\u200b&#xff1a;\u4e1a\u52a1\u903b\u8f91\u8f7d\u4f53&#xff08;\u5982\u7f16\u89e3\u7801\u3001\u65e5\u5fd7\u8bb0\u5f55\u3001\u6570\u636e\u8f6c\u53d1&#xff09;\u3002<\/li>\n<\/ul>\n<h6>2.3 Netty\u7684\u4f18\u52bf<\/h6>\n<ul>\n<li>\u200b\u200b\u9ad8\u6027\u80fd\u200b\u200b&#xff1a;\u57fa\u4e8eNIO\u7684\u975e\u963b\u585eIO\u6a21\u578b&#xff0c;\u5355\u7ebf\u7a0b\u53ef\u5904\u7406\u6570\u4e07\u8fde\u63a5\u3002<\/li>\n<li>\u200b\u200b\u6613\u6269\u5c55\u200b\u200b&#xff1a;\u901a\u8fc7\u81ea\u5b9a\u4e49Handler\u7075\u6d3b\u6269\u5c55\u529f\u80fd&#xff08;\u5982\u534f\u8bae\u89e3\u6790\u3001\u6d41\u91cf\u63a7\u5236&#xff09;\u3002<\/li>\n<li>\u200b\u200b\u8de8\u5e73\u53f0\u200b\u200b&#xff1a;\u652f\u6301Linux\u3001Windows\u7b49\u591a\u7cfb\u7edf\u3002<\/li>\n<\/ul>\n<h5>\u4e09\u3001\u5b9e\u6218\u6848\u4f8b&#xff1a;Netty\u5b9e\u73b0Echo\u670d\u52a1\u5668<\/h5>\n<h6>3.1 \u9700\u6c42\u8bf4\u660e<\/h6>\n<p>\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u200b\u200bEcho\u670d\u52a1\u5668\u200b\u200b&#xff1a;\u5ba2\u6237\u7aef\u53d1\u9001\u4efb\u610f\u6d88\u606f&#xff0c;\u670d\u52a1\u5668\u63a5\u6536\u540e\u539f\u6837\u8fd4\u56de\u3002\u8be5\u6848\u4f8b\u53ef\u6f14\u793aNetty\u7684\u6838\u5fc3\u6d41\u7a0b&#xff08;\u670d\u52a1\u7aef\u542f\u52a8\u3001\u4e8b\u4ef6\u5904\u7406\u3001\u5ba2\u6237\u7aef\u4ea4\u4e92&#xff09;\u3002<\/p>\n<h6>3.2 \u73af\u5883\u51c6\u5907<\/h6>\n<ul>\n<li>JDK 8&#043;<\/li>\n<li>Maven 3.6&#043;<\/li>\n<li>Netty\u4f9d\u8d56&#xff08;4.1.x\u7a33\u5b9a\u7248&#xff09;<\/li>\n<\/ul>\n<p>\u5728pom.xml\u4e2d\u6dfb\u52a0\u4f9d\u8d56&#xff1a;<\/p>\n<p>&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;io.netty&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;netty-all&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;4.1.96.Final&lt;\/version&gt;<br \/>\n&lt;\/dependency&gt; <\/p>\n<h6>3.3 \u670d\u52a1\u7aef\u4ee3\u7801\u5b9e\u73b0<\/h6>\n<p>\u670d\u52a1\u7aef\u6838\u5fc3\u6d41\u7a0b&#xff1a;\u521b\u5efaEventLoopGroup\u2192\u914d\u7f6eServerBootstrap\u2192\u7ed1\u5b9a\u7aef\u53e3\u2192\u542f\u52a8\u670d\u52a1\u3002<\/p>\n<p>import io.netty.bootstrap.ServerBootstrap;<br \/>\nimport io.netty.channel.*;<br \/>\nimport io.netty.channel.nio.NioEventLoopGroup;<br \/>\nimport io.netty.channel.socket.SocketChannel;<br \/>\nimport io.netty.channel.socket.nio.NioServerSocketChannel;<br \/>\nimport io.netty.handler.codec.string.StringDecoder;<br \/>\nimport io.netty.handler.codec.string.StringEncoder;<\/p>\n<p>public class EchoServer {<br \/>\n    private final int port;<\/p>\n<p>    public EchoServer(int port) {<br \/>\n        this.port &#061; port;<br \/>\n    }<\/p>\n<p>    public void start() throws Exception {<br \/>\n        \/\/ 1. \u521b\u5efa\u4e24\u4e2aEventLoopGroup&#xff1a;bossGroup\u5904\u7406\u8fde\u63a5\u8bf7\u6c42&#xff0c;workerGroup\u5904\u7406IO<br \/>\n        EventLoopGroup bossGroup &#061; new NioEventLoopGroup(1); \/\/ 1\u4e2a\u7ebf\u7a0b\u5904\u7406\u8fde\u63a5<br \/>\n        EventLoopGroup workerGroup &#061; new NioEventLoopGroup(); \/\/ \u9ed8\u8ba4CPU\u6838\u5fc3\u6570\u7ebf\u7a0b\u5904\u7406IO<\/p>\n<p>        try {<br \/>\n            \/\/ 2. \u914d\u7f6e\u670d\u52a1\u7aef\u542f\u52a8\u5668<br \/>\n            ServerBootstrap b &#061; new ServerBootstrap();<br \/>\n            b.group(bossGroup, workerGroup)<br \/>\n             .channel(NioServerSocketChannel.class) \/\/ \u4f7f\u7528NIO\u4f20\u8f93<br \/>\n             .childHandler(new ChannelInitializer&lt;SocketChannel&gt;() { \/\/ \u5b50\u5904\u7406\u5668&#xff08;\u5ba2\u6237\u7aef\u8fde\u63a5\u540e\u89e6\u53d1&#xff09;<br \/>\n                 &#064;Override<br \/>\n                 protected void initChannel(SocketChannel ch) {<br \/>\n                     \/\/ 3. \u6784\u5efa\u5904\u7406\u5668\u94fe&#xff1a;\u89e3\u7801\u2192\u4e1a\u52a1\u5904\u7406\u2192\u7f16\u7801<br \/>\n                     ChannelPipeline pipeline &#061; ch.pipeline();<br \/>\n                     pipeline.addLast(new StringDecoder());   \/\/ \u5b57\u7b26\u4e32\u89e3\u7801\u5668&#xff08;\u5c06ByteBuf\u8f6cString&#xff09;<br \/>\n                     pipeline.addLast(new StringEncoder());  \/\/ \u5b57\u7b26\u4e32\u7f16\u7801\u5668&#xff08;\u5c06String\u8f6cByteBuf&#xff09;<br \/>\n                     pipeline.addLast(new EchoServerHandler()); \/\/ \u81ea\u5b9a\u4e49\u4e1a\u52a1\u5904\u7406\u5668<br \/>\n                 }<br \/>\n             })<br \/>\n             .option(ChannelOption.SO_BACKLOG, 128) \/\/ \u8fde\u63a5\u961f\u5217\u5927\u5c0f<br \/>\n             .childOption(ChannelOption.SO_KEEPALIVE, true); \/\/ \u4fdd\u6301\u957f\u8fde\u63a5<\/p>\n<p>            \/\/ 4. \u7ed1\u5b9a\u7aef\u53e3\u5e76\u542f\u52a8\u670d\u52a1<br \/>\n            ChannelFuture f &#061; b.bind(port).sync();<br \/>\n            System.out.println(&#034;Echo\u670d\u52a1\u5668\u542f\u52a8&#xff0c;\u7aef\u53e3&#xff1a;&#034; &#043; port);<\/p>\n<p>            \/\/ 5. \u7b49\u5f85\u670d\u52a1\u7aef\u5173\u95ed<br \/>\n            f.channel().closeFuture().sync();<br \/>\n        } finally {<br \/>\n            \/\/ 6. \u4f18\u96c5\u5173\u95ed\u7ebf\u7a0b\u6c60<br \/>\n            bossGroup.shutdownGracefully();<br \/>\n            workerGroup.shutdownGracefully();<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws Exception {<br \/>\n        new EchoServer(8080).start();<br \/>\n    }<br \/>\n} <\/p>\n<h6>3.4 \u81ea\u5b9a\u4e49\u4e1a\u52a1\u5904\u7406\u5668&#xff08;EchoServerHandler&#xff09;<\/h6>\n<p>\u5904\u7406\u5ba2\u6237\u7aef\u6d88\u606f\u5e76\u56de\u5199&#xff1a;<\/p>\n<p>import io.netty.channel.ChannelHandlerContext;<br \/>\nimport io.netty.channel.ChannelInboundHandlerAdapter;<\/p>\n<p>public class EchoServerHandler extends ChannelInboundHandlerAdapter {<br \/>\n    &#064;Override<br \/>\n    public void channelRead(ChannelHandlerContext ctx, Object msg) {<br \/>\n        \/\/ \u76f4\u63a5\u4f7f\u7528ctx.writeAndFlush\u56de\u5199\u6d88\u606f&#xff08;\u81ea\u52a8\u7f16\u7801&#xff09;<br \/>\n        ctx.writeAndFlush(msg);<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {<br \/>\n        \/\/ \u5f02\u5e38\u5904\u7406&#xff1a;\u6253\u5370\u65e5\u5fd7\u5e76\u5173\u95ed\u8fde\u63a5<br \/>\n        cause.printStackTrace();<br \/>\n        ctx.close();<br \/>\n    }<br \/>\n} <\/p>\n<h6>3.5 \u5ba2\u6237\u7aef\u4ee3\u7801\u5b9e\u73b0<\/h6>\n<p>\u5ba2\u6237\u7aef\u6838\u5fc3\u6d41\u7a0b&#xff1a;\u8fde\u63a5\u670d\u52a1\u7aef\u2192\u53d1\u9001\u6d88\u606f\u2192\u63a5\u6536\u54cd\u5e94\u3002<\/p>\n<p>import io.netty.bootstrap.Bootstrap;<br \/>\nimport io.netty.channel.*;<br \/>\nimport io.netty.channel.nio.NioEventLoopGroup;<br \/>\nimport io.netty.channel.socket.SocketChannel;<br \/>\nimport io.netty.channel.socket.nio.NioSocketChannel;<br \/>\nimport io.netty.handler.codec.string.StringDecoder;<br \/>\nimport io.netty.handler.codec.string.StringEncoder;<\/p>\n<p>public class EchoClient {<br \/>\n    private final String host;<br \/>\n    private final int port;<\/p>\n<p>    public EchoClient(String host, int port) {<br \/>\n        this.host &#061; host;<br \/>\n        this.port &#061; port;<br \/>\n    }<\/p>\n<p>    public void start() throws Exception {<br \/>\n        EventLoopGroup group &#061; new NioEventLoopGroup();<\/p>\n<p>        try {<br \/>\n            Bootstrap b &#061; new Bootstrap();<br \/>\n            b.group(group)<br \/>\n             .channel(NioSocketChannel.class)<br \/>\n             .handler(new ChannelInitializer&lt;SocketChannel&gt;() {<br \/>\n                 &#064;Override<br \/>\n                 protected void initChannel(SocketChannel ch) {<br \/>\n                     ChannelPipeline pipeline &#061; ch.pipeline();<br \/>\n                     pipeline.addLast(new StringDecoder());<br \/>\n                     pipeline.addLast(new StringEncoder());<br \/>\n                     pipeline.addLast(new EchoClientHandler()); \/\/ \u5ba2\u6237\u7aef\u4e1a\u52a1\u5904\u7406\u5668<br \/>\n                 }<br \/>\n             });<\/p>\n<p>            \/\/ \u8fde\u63a5\u670d\u52a1\u7aef<br \/>\n            ChannelFuture f &#061; b.connect(host, port).sync();<br \/>\n            Channel channel &#061; f.channel();<\/p>\n<p>            \/\/ \u53d1\u9001\u6d4b\u8bd5\u6d88\u606f<br \/>\n            String message &#061; &#034;Hello, Netty!&#034;;<br \/>\n            channel.writeAndFlush(message);<br \/>\n            System.out.println(&#034;\u5ba2\u6237\u7aef\u53d1\u9001&#xff1a;&#034; &#043; message);<\/p>\n<p>            \/\/ \u7b49\u5f85\u5173\u95ed<br \/>\n            f.channel().closeFuture().sync();<br \/>\n        } finally {<br \/>\n            group.shutdownGracefully();<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws Exception {<br \/>\n        new EchoClient(&#034;127.0.0.1&#034;, 8080).start();<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u5ba2\u6237\u7aef\u4e1a\u52a1\u5904\u7406\u5668&#xff08;\u53ef\u9009&#xff0c;\u6b64\u5904\u53ef\u76f4\u63a5\u5728main\u4e2d\u53d1\u9001&#xff09;<br \/>\nclass EchoClientHandler extends ChannelInboundHandlerAdapter {<br \/>\n    &#064;Override<br \/>\n    public void channelRead(ChannelHandlerContext ctx, Object msg) {<br \/>\n        System.out.println(&#034;\u5ba2\u6237\u7aef\u63a5\u6536&#xff1a;&#034; &#043; msg);<br \/>\n    }<br \/>\n} <\/p>\n<h5>\u56db\u3001Netty\u7684\u5178\u578b\u4f7f\u7528\u573a\u666f<\/h5>\n<h6>4.1 \u9ad8\u6027\u80fdRPC\u6846\u67b6&#xff08;\u5982Dubbo\u3001gRPC&#xff09;<\/h6>\n<p>RPC\u6846\u67b6\u9700\u8981\u9ad8\u6548\u7684\u8de8\u8fdb\u7a0b\u901a\u4fe1&#xff0c;Netty\u7684\u5f02\u6b65\u975e\u963b\u585e\u6a21\u578b\u80fd\u652f\u6491\u9ad8\u5e76\u53d1\u8fde\u63a5&#xff0c;\u914d\u5408\u81ea\u5b9a\u4e49\u7f16\u89e3\u7801\u5668&#xff08;\u5982Protobuf&#xff09;\u5b9e\u73b0\u4f4e\u5ef6\u8fdf\u6570\u636e\u4f20\u8f93\u3002<\/p>\n<h6>4.2 \u5373\u65f6\u901a\u8baf\u7cfb\u7edf&#xff08;IM&#xff09;<\/h6>\n<p>IM\u9700\u8981\u957f\u8fde\u63a5\u7ef4\u6301\u548c\u9ad8\u5e76\u53d1\u6d88\u606f\u5904\u7406&#xff0c;Netty\u7684EventLoop\u53ef\u9ad8\u6548\u7ba1\u7406\u6570\u4e07\u957f\u8fde\u63a5&#xff0c;\u652f\u6301\u5fc3\u8df3\u68c0\u6d4b\u3001\u6d88\u606f\u5e7f\u64ad\u7b49\u529f\u80fd\u3002<\/p>\n<h6>4.3 \u6e38\u620f\u670d\u52a1\u5668<\/h6>\n<p>\u6e38\u620f\u670d\u52a1\u5668\u9700\u5904\u7406\u5927\u91cf\u73a9\u5bb6\u5b9e\u65f6\u4ea4\u4e92&#xff08;\u5982\u79fb\u52a8\u3001\u6218\u6597\u6307\u4ee4&#xff09;&#xff0c;Netty\u7684\u4f4e\u5ef6\u8fdfIO\u548c\u7075\u6d3b\u7684\u5904\u7406\u5668\u94fe\u80fd\u6ee1\u8db3\u9ad8\u5e76\u53d1\u3001\u4f4e\u5ef6\u8fdf\u9700\u6c42\u3002<\/p>\n<h6>4.4 HTTP\u670d\u52a1\u5668\/\u5ba2\u6237\u7aef&#xff08;\u5982Spring WebFlux&#xff09;<\/h6>\n<p>Spring WebFlux\u5e95\u5c42\u57fa\u4e8eReactor Netty\u5b9e\u73b0&#xff0c;\u5229\u7528Netty\u7684\u5f02\u6b65\u975e\u963b\u585e\u7279\u6027\u652f\u6301\u54cd\u5e94\u5f0f\u7f16\u7a0b&#xff0c;\u5904\u7406\u9ad8\u5e76\u53d1HTTP\u8bf7\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb848\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u7f51\u7edc\u7f16\u7a0b\u662f\u6307\u901a\u8fc7\u200b\u200b\u7f51\u7edc\u534f\u8bae\uff08\u5982TCP\/IP\uff09\u200b\u200b\u5b9e\u73b0\u4e0d\u540c\u8bbe\u5907\u95f4\u6570\u636e\u901a\u4fe1\u7684\u6280\u672f\u3002\u6838\u5fc3\u76ee\u6807\u662f\u8ba9\u7a0b\u5e8f\u80fd\u591f\u901a\u8fc7\u7f51\u7edc\u4e0e\u5176\u4ed6\u7a0b\u5e8f\u4ea4\u6362\u6570\u636e\uff0c\u4f8b\u5982\u7f51\u9875\u6d4f\u89c8\u3001\u5373\u65f6\u901a\u8baf\u3001\u6587\u4ef6\u4f20\u8f93\u7b49\u573a\u666f\u5747\u4f9d\u8d56\u7f51\u7edc\u7f16\u7a0b\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[43,78,44],"topic":[],"class_list":["post-45221","post","type-post","status-publish","format-standard","hentry","category-server","tag-43","tag-78","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7f51\u7edc\u7f16\u7a0b\u7b80\u4ecb\u4e0eNetty\u5b9e\u6218\uff1a\u4ece\u5165\u95e8\u5230\u9ad8\u6027\u80fdEcho\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/45221.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7f51\u7edc\u7f16\u7a0b\u7b80\u4ecb\u4e0eNetty\u5b9e\u6218\uff1a\u4ece\u5165\u95e8\u5230\u9ad8\u6027\u80fdEcho\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb848\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u7f51\u7edc\u7f16\u7a0b\u662f\u6307\u901a\u8fc7\u200b\u200b\u7f51\u7edc\u534f\u8bae\uff08\u5982TCP\/IP\uff09\u200b\u200b\u5b9e\u73b0\u4e0d\u540c\u8bbe\u5907\u95f4\u6570\u636e\u901a\u4fe1\u7684\u6280\u672f\u3002\u6838\u5fc3\u76ee\u6807\u662f\u8ba9\u7a0b\u5e8f\u80fd\u591f\u901a\u8fc7\u7f51\u7edc\u4e0e\u5176\u4ed6\u7a0b\u5e8f\u4ea4\u6362\u6570\u636e\uff0c\u4f8b\u5982\u7f51\u9875\u6d4f\u89c8\u3001\u5373\u65f6\u901a\u8baf\u3001\u6587\u4ef6\u4f20\u8f93\u7b49\u573a\u666f\u5747\u4f9d\u8d56\u7f51\u7edc\u7f16\u7a0b\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/45221.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-22T23:16:15+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/45221.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/45221.html\",\"name\":\"\u7f51\u7edc\u7f16\u7a0b\u7b80\u4ecb\u4e0eNetty\u5b9e\u6218\uff1a\u4ece\u5165\u95e8\u5230\u9ad8\u6027\u80fdEcho\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-06-22T23:16:15+00:00\",\"dateModified\":\"2025-06-22T23:16:15+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/45221.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/45221.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/45221.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7f51\u7edc\u7f16\u7a0b\u7b80\u4ecb\u4e0eNetty\u5b9e\u6218\uff1a\u4ece\u5165\u95e8\u5230\u9ad8\u6027\u80fdEcho\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7f51\u7edc\u7f16\u7a0b\u7b80\u4ecb\u4e0eNetty\u5b9e\u6218\uff1a\u4ece\u5165\u95e8\u5230\u9ad8\u6027\u80fdEcho\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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":"https:\/\/www.wsisp.com\/helps\/45221.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7f51\u7edc\u7f16\u7a0b\u7b80\u4ecb\u4e0eNetty\u5b9e\u6218\uff1a\u4ece\u5165\u95e8\u5230\u9ad8\u6027\u80fdEcho\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb848\u6b21\uff0c\u70b9\u8d5e13\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u7f51\u7edc\u7f16\u7a0b\u662f\u6307\u901a\u8fc7\u200b\u200b\u7f51\u7edc\u534f\u8bae\uff08\u5982TCP\/IP\uff09\u200b\u200b\u5b9e\u73b0\u4e0d\u540c\u8bbe\u5907\u95f4\u6570\u636e\u901a\u4fe1\u7684\u6280\u672f\u3002\u6838\u5fc3\u76ee\u6807\u662f\u8ba9\u7a0b\u5e8f\u80fd\u591f\u901a\u8fc7\u7f51\u7edc\u4e0e\u5176\u4ed6\u7a0b\u5e8f\u4ea4\u6362\u6570\u636e\uff0c\u4f8b\u5982\u7f51\u9875\u6d4f\u89c8\u3001\u5373\u65f6\u901a\u8baf\u3001\u6587\u4ef6\u4f20\u8f93\u7b49\u573a\u666f\u5747\u4f9d\u8d56\u7f51\u7edc\u7f16\u7a0b\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/45221.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-06-22T23:16:15+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/45221.html","url":"https:\/\/www.wsisp.com\/helps\/45221.html","name":"\u7f51\u7edc\u7f16\u7a0b\u7b80\u4ecb\u4e0eNetty\u5b9e\u6218\uff1a\u4ece\u5165\u95e8\u5230\u9ad8\u6027\u80fdEcho\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-06-22T23:16:15+00:00","dateModified":"2025-06-22T23:16:15+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/45221.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/45221.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/45221.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7f51\u7edc\u7f16\u7a0b\u7b80\u4ecb\u4e0eNetty\u5b9e\u6218\uff1a\u4ece\u5165\u95e8\u5230\u9ad8\u6027\u80fdEcho\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/45221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=45221"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/45221\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=45221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=45221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=45221"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=45221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}