{"id":35090,"date":"2025-05-02T12:45:52","date_gmt":"2025-05-02T04:45:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/35090.html"},"modified":"2025-05-02T12:45:52","modified_gmt":"2025-05-02T04:45:52","slug":"netty%e9%ab%98%e5%b9%b6%e5%8f%91%e7%89%a9%e8%81%94%e7%bd%91%e9%80%9a%e4%bf%a1%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%ae%9e%e6%88%98%ef%bc%9a%e5%8d%8f%e8%ae%ae%e4%bc%98%e5%8c%96%e4%b8%8e%e6%80%a7%e8%83%bd","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/35090.html","title":{"rendered":"Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"1.%E6%80%BB%E4%BD%93%E8%AE%BE%E8%AE%A1-toc\" style=\"margin-left:0px\">1.\u603b\u4f53\u8bbe\u8ba1<\/p>\n<p id=\"2.%E8%87%AA%E5%AE%9A%E4%B9%89%E5%8D%8F%E8%AE%AE%E8%AE%BE%E8%AE%A1%EF%BC%88%E7%AE%80%E5%8D%95%E7%89%88%EF%BC%89-toc\" style=\"margin-left:0px\">2.\u81ea\u5b9a\u4e49\u534f\u8bae\u8bbe\u8ba1\uff08\u7b80\u5355\u7248\uff09<\/p>\n<p id=\"3.%E6%B6%88%E6%81%AF%E7%B1%BB%E5%9E%8B%EF%BC%881%E5%AD%97%E8%8A%82%EF%BC%89-toc\" style=\"margin-left:0px\">3.\u6d88\u606f\u7c7b\u578b\uff081\u5b57\u8282\uff09<\/p>\n<p id=\"4.%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84-toc\" style=\"margin-left:0px\">4.\u9879\u76ee\u7ed3\u6784<\/p>\n<p id=\"5.%E6%A0%B8%E5%BF%83%E5%8A%9F%E8%83%BD%E4%BB%A3%E7%A0%81-toc\" style=\"margin-left:0px\">5.\u6838\u5fc3\u529f\u80fd\u4ee3\u7801<\/p>\n<p id=\"%EF%BC%881%EF%BC%89pom.xml%EF%BC%88Maven%E4%BE%9D%E8%B5%96%EF%BC%89-toc\" style=\"margin-left:40px\">\uff081\uff09pom.xml\uff08Maven\u4f9d\u8d56\uff09<\/p>\n<p id=\"%EF%BC%882%EF%BC%89IotServer.java%EF%BC%88%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%90%AF%E5%8A%A8%E5%99%A8%EF%BC%89-toc\" style=\"margin-left:40px\">\uff082\uff09IotServer.java\uff08\u670d\u52a1\u5668\u542f\u52a8\u5668\uff09<\/p>\n<p id=\"%EF%BC%883%EF%BC%89IotServerInitializer.java%EF%BC%88Pipeline%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%89-toc\" style=\"margin-left:40px\">\uff083\uff09IotServerInitializer.java\uff08Pipeline\u521d\u59cb\u5316\uff09<\/p>\n<p id=\"%EF%BC%885%EF%BC%89DeviceChannelManager.java%EF%BC%88%E8%AE%BE%E5%A4%87%E8%BF%9E%E6%8E%A5%E7%AE%A1%E7%90%86%E5%99%A8%EF%BC%89-toc\" style=\"margin-left:40px\">\uff084\uff09DeviceChannelManager.java\uff08\u8bbe\u5907\u8fde\u63a5\u7ba1\u7406\u5668\uff09<\/p>\n<p id=\"%EF%BC%884%EF%BC%89model%2FIotMessage.java%EF%BC%88%E6%B6%88%E6%81%AF%E5%AE%9E%E4%BD%93%EF%BC%89-toc\" style=\"margin-left:40px\">\uff085\uff09model\/IotMessage.java\uff08\u6d88\u606f\u5b9e\u4f53\uff09<\/p>\n<p id=\"%EF%BC%885%EF%BC%89IotMessageDecoder.java%EF%BC%88%E8%87%AA%E5%AE%9A%E4%B9%89%E8%A7%A3%E7%A0%81%E5%99%A8%EF%BC%89-toc\" style=\"margin-left:40px\">\uff086\uff09IotMessageDecoder.java\uff08\u81ea\u5b9a\u4e49\u89e3\u7801\u5668\uff09<\/p>\n<p id=\"%EF%BC%886%EF%BC%89IotMessageEncoder.java%EF%BC%88%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BC%96%E7%A0%81%E5%99%A8%EF%BC%89-toc\" style=\"margin-left:40px\">\uff087\uff09IotMessageEncoder.java\uff08\u81ea\u5b9a\u4e49\u7f16\u7801\u5668\uff09<\/p>\n<p id=\"%EF%BC%887%EF%BC%89IotServerHandler.java%EF%BC%88%E6%A0%B8%E5%BF%83%E4%B8%9A%E5%8A%A1%E9%80%BB%E8%BE%91%E5%A4%84%E7%90%86%EF%BC%89-toc\" style=\"margin-left:40px\">\uff088\uff09IotServerHandler.java\uff08\u6838\u5fc3\u4e1a\u52a1\u903b\u8f91\u5904\u7406\uff09<\/p>\n<p id=\"%E8%BF%99%E4%B8%AA%E9%A1%B9%E7%9B%AE%E5%B7%B2%E7%BB%8F%E6%94%AF%E6%8C%81%E4%BA%86%EF%BC%9A-toc\" style=\"margin-left:40px\">\u8fd9\u4e2a\u9879\u76ee\u5df2\u7ecf\u652f\u6301\u4e86\uff1a<\/p>\n<p id=\"6.Netty%E7%89%A9%E8%81%94%E7%BD%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E5%8F%8A%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:0px\">6.Netty\u7269\u8054\u7f51\u670d\u52a1\u5668\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/p>\n<p id=\"%EF%BC%881%EF%BC%89%E7%B2%98%E5%8C%85%2F%E6%8B%86%E5%8C%85%E9%97%AE%E9%A2%98-toc\" style=\"margin-left:40px\">\uff081\uff09\u7c98\u5305\/\u62c6\u5305\u95ee\u9898<\/p>\n<p id=\"%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0-toc\" style=\"margin-left:80px\">\u95ee\u9898\u63cf\u8ff0<\/p>\n<p id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:80px\">\u89e3\u51b3\u65b9\u6848<\/p>\n<p id=\"%EF%BC%882%EF%BC%89%E9%AB%98%E5%B9%B6%E5%8F%91%E6%80%A7%E8%83%BD%E9%97%AE%E9%A2%98-toc\" style=\"margin-left:40px\">\uff082\uff09\u9ad8\u5e76\u53d1\u6027\u80fd\u95ee\u9898<\/p>\n<p id=\"%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0-toc\" style=\"margin-left:80px\">\u95ee\u9898\u63cf\u8ff0<\/p>\n<p id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:80px\">\u89e3\u51b3\u65b9\u6848<\/p>\n<p id=\"%EF%BC%883%EF%BC%89%E8%BF%9E%E6%8E%A5%E7%AE%A1%E7%90%86%E4%B8%8E%E9%AB%98%E5%8F%AF%E7%94%A8%E6%80%A7-toc\" style=\"margin-left:40px\">\uff083\uff09\u8fde\u63a5\u7ba1\u7406\u4e0e\u9ad8\u53ef\u7528\u6027<\/p>\n<p id=\"%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0-toc\" style=\"margin-left:80px\">\u95ee\u9898\u63cf\u8ff0<\/p>\n<p id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:80px\">\u89e3\u51b3\u65b9\u6848<\/p>\n<p id=\"%EF%BC%884%EF%BC%89%E5%8D%8F%E8%AE%AE%E5%85%BC%E5%AE%B9%E6%80%A7%E4%B8%8E%E6%89%A9%E5%B1%95%E6%80%A7-toc\" style=\"margin-left:40px\">\uff084\uff09\u534f\u8bae\u517c\u5bb9\u6027\u4e0e\u6269\u5c55\u6027<\/p>\n<p id=\"%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0-toc\" style=\"margin-left:80px\">\u95ee\u9898\u63cf\u8ff0<\/p>\n<p id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:80px\">\u89e3\u51b3\u65b9\u6848<\/p>\n<p id=\"%EF%BC%885%EF%BC%89%E8%B5%84%E6%BA%90%E6%B3%84%E6%BC%8F%E4%B8%8E%E7%A8%B3%E5%AE%9A%E6%80%A7-toc\" style=\"margin-left:40px\">\uff085\uff09\u8d44\u6e90\u6cc4\u6f0f\u4e0e\u7a33\u5b9a\u6027<\/p>\n<p id=\"%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0-toc\" style=\"margin-left:80px\">\u95ee\u9898\u63cf\u8ff0<\/p>\n<p id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:80px\">\u89e3\u51b3\u65b9\u6848<\/p>\n<p id=\"%EF%BC%886%EF%BC%89%E5%BC%B1%E7%BD%91%E7%BB%9C%E7%8E%AF%E5%A2%83%E9%80%82%E9%85%8D-toc\" style=\"margin-left:40px\">\uff086\uff09\u5f31\u7f51\u7edc\u73af\u5883\u9002\u914d<\/p>\n<p id=\"%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0-toc\" style=\"margin-left:80px\">\u95ee\u9898\u63cf\u8ff0<\/p>\n<p id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:80px\">\u89e3\u51b3\u65b9\u6848<\/p>\n<p id=\"%EF%BC%887%EF%BC%89%E5%AE%89%E5%85%A8%E4%B8%8E%E5%8A%A0%E5%AF%86-toc\" style=\"margin-left:40px\">\uff087\uff09\u5b89\u5168\u4e0e\u52a0\u5bc6<\/p>\n<p id=\"%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0-toc\" style=\"margin-left:80px\">\u95ee\u9898\u63cf\u8ff0<\/p>\n<p id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:80px\">\u89e3\u51b3\u65b9\u6848<\/p>\n<p id=\"%EF%BC%888%EF%BC%89%E7%9B%91%E6%8E%A7%E4%B8%8E%E6%97%A5%E5%BF%97-toc\" style=\"margin-left:40px\">\uff088\uff09\u76d1\u63a7\u4e0e\u65e5\u5fd7<\/p>\n<p id=\"%E9%97%AE%E9%A2%98%E6%8F%8F%E8%BF%B0-toc\" style=\"margin-left:80px\">\u95ee\u9898\u63cf\u8ff0<\/p>\n<p id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:80px\">\u89e3\u51b3\u65b9\u6848<\/p>\n<p style=\"margin-left:80px\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"2464\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250502044548-68144dfc17b0b.png\" width=\"3936\"><\/p>\n<h2 id=\"1.%E6%80%BB%E4%BD%93%E8%AE%BE%E8%AE%A1\">1.\u603b\u4f53\u8bbe\u8ba1<\/h2>\n<table>\n<tbody>\n<tr>\n<td>\u6a21\u5757<\/td>\n<td>\u8bf4\u660e<\/td>\n<\/tr>\n<tr>\n<td>\u8bbe\u5907\u8fde\u63a5\uff08Login\uff09<\/td>\n<td>\u8bbe\u5907\u4e0a\u7ebf\u65f6\u767b\u5f55\u8ba4\u8bc1<\/td>\n<\/tr>\n<tr>\n<td>\u5fc3\u8df3\u68c0\u6d4b\uff08Heartbeat\uff09<\/td>\n<td>\u5b9a\u65f6\u68c0\u6d4b\u8bbe\u5907\u662f\u5426\u5728\u7ebf<\/td>\n<\/tr>\n<tr>\n<td>\u6d88\u606f\u4e0a\u62a5\uff08Upload\uff09<\/td>\n<td>\u8bbe\u5907\u4e3b\u52a8\u4e0a\u4f20\u6570\u636e\u5230\u5e73\u53f0<\/td>\n<\/tr>\n<tr>\n<td>\u6307\u4ee4\u4e0b\u53d1\uff08PushCommand\uff09<\/td>\n<td>\u5e73\u53f0\u63a8\u9001\u547d\u4ee4\u5230\u6307\u5b9a\u8bbe\u5907<\/td>\n<\/tr>\n<tr>\n<td>\u8fde\u63a5\u7ba1\u7406\uff08Channel\u7ba1\u7406\uff09<\/td>\n<td>\u6309 deviceId \u7ba1\u7406\u8fde\u63a5<\/td>\n<\/tr>\n<tr>\n<td>\u7f16\u89e3\u7801\u5668\uff08\u81ea\u5b9a\u4e49\u534f\u8bae\uff09<\/td>\n<td>\u5904\u7406\u6d88\u606f\u7c98\u5305\u3001\u62c6\u5305<\/td>\n<\/tr>\n<tr>\n<td>\u65e5\u5fd7\u76d1\u63a7<\/td>\n<td>\u8bb0\u5f55\u901a\u4fe1\u8fc7\u7a0b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2 id=\"2.%E8%87%AA%E5%AE%9A%E4%B9%89%E5%8D%8F%E8%AE%AE%E8%AE%BE%E8%AE%A1%EF%BC%88%E7%AE%80%E5%8D%95%E7%89%88%EF%BC%89\">2.\u81ea\u5b9a\u4e49\u534f\u8bae\u8bbe\u8ba1\uff08\u7b80\u5355\u7248\uff09<\/h2>\n<p>\u8bbe\u5907\u548c\u5e73\u53f0\u7ea6\u5b9a\u7684\u6d88\u606f\u683c\u5f0f\uff0c\u7edf\u4e00\u89c4\u8303\u901a\u4fe1\uff01<\/p>\n<p>+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| \u6d88\u606f\u5934\u90e8 | \u6d88\u606f\u7c7b\u578b | \u8bbe\u5907ID\u957f\u5ea6 | \u6d88\u606f\u4f53\u957f\u5ea6    |<br \/>\n| 4\u5b57\u8282    | 1\u5b57\u8282   | 1\u5b57\u8282     | 4\u5b57\u8282        |<br \/>\n+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| \u8bbe\u5907ID (\u53d8\u957f) | \u6d88\u606f\u4f53 (\u53d8\u957f)                     |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+ <\/p>\n<h2 id=\"3.%E6%B6%88%E6%81%AF%E7%B1%BB%E5%9E%8B%EF%BC%881%E5%AD%97%E8%8A%82%EF%BC%89\">3.\u6d88\u606f\u7c7b\u578b\uff081\u5b57\u8282\uff09<\/h2>\n<table>\n<tbody>\n<tr>\n<td>\u7c7b\u578b\u503c<\/td>\n<td>\u542b\u4e49<\/td>\n<\/tr>\n<tr>\n<td>0x01<\/td>\n<td>\u767b\u5f55\u8bf7\u6c42<\/td>\n<\/tr>\n<tr>\n<td>0x02<\/td>\n<td>\u5fc3\u8df3<\/td>\n<\/tr>\n<tr>\n<td>0x03<\/td>\n<td>\u4e0a\u62a5\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>0x04<\/td>\n<td>\u5e73\u53f0\u63a8\u9001\u547d\u4ee4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2 id=\"4.%E9%A1%B9%E7%9B%AE%E7%BB%93%E6%9E%84\">4.\u9879\u76ee\u7ed3\u6784<\/h2>\n<p>iot-netty-server\/<br \/>\n \u251c\u2500\u2500 IotServer.java                \/\/ \u542f\u52a8\u670d\u52a1\u5668<br \/>\n \u251c\u2500\u2500 IotServerInitializer.java     \/\/ \u521d\u59cb\u5316Pipeline<br \/>\n \u251c\u2500\u2500 IotMessageDecoder.java         \/\/ \u89e3\u7801\u5668<br \/>\n \u251c\u2500\u2500 IotMessageEncoder.java         \/\/ \u7f16\u7801\u5668<br \/>\n \u251c\u2500\u2500 IotServerHandler.java          \/\/ \u6838\u5fc3\u4e1a\u52a1\u5904\u7406<br \/>\n \u251c\u2500\u2500 DeviceChannelManager.java      \/\/ \u8fde\u63a5\u7ba1\u7406<br \/>\n \u251c\u2500\u2500 model\/<br \/>\n \u2502   \u251c\u2500\u2500 IotMessage.java            \/\/ \u6d88\u606f\u6a21\u578b<br \/>\n \u2514\u2500\u2500 pom.xml                        \/\/ Maven\u4f9d\u8d56 <\/p>\n<hr>\n<h2 id=\"5.%E6%A0%B8%E5%BF%83%E5%8A%9F%E8%83%BD%E4%BB%A3%E7%A0%81\">5.\u6838\u5fc3\u529f\u80fd\u4ee3\u7801<\/h2>\n<hr>\n<h3 id=\"%EF%BC%881%EF%BC%89pom.xml%EF%BC%88Maven%E4%BE%9D%E8%B5%96%EF%BC%89\">\uff081\uff09pom.xml\uff08Maven\u4f9d\u8d56\uff09<\/h3>\n<p>&lt;dependencies&gt;<br \/>\n    &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.109.Final&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n&lt;\/dependencies&gt; <\/p>\n<hr>\n<h3 id=\"%EF%BC%882%EF%BC%89IotServer.java%EF%BC%88%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%90%AF%E5%8A%A8%E5%99%A8%EF%BC%89\">\uff082\uff09IotServer.java\uff08\u670d\u52a1\u5668\u542f\u52a8\u5668\uff09<\/h3>\n<p>public class IotServer {<br \/>\n    public static void main(String[] args) throws Exception {<br \/>\n        EventLoopGroup bossGroup = new NioEventLoopGroup(1);<br \/>\n        EventLoopGroup workerGroup = new NioEventLoopGroup();<\/p>\n<p>        try {<br \/>\n            ServerBootstrap b = new ServerBootstrap();<br \/>\n            b.group(bossGroup, workerGroup)<br \/>\n             .channel(NioServerSocketChannel.class)<br \/>\n             .childHandler(new IotServerInitializer());<\/p>\n<p>            ChannelFuture f = b.bind(9000).sync();<br \/>\n            System.out.println(\\&#8221;IoT\u670d\u52a1\u5668\u542f\u52a8\u6210\u529f\uff0c\u76d1\u542c\u7aef\u53e39000&#8230;\\&#8221;);<br \/>\n            f.channel().closeFuture().sync();<br \/>\n        } finally {<br \/>\n            bossGroup.shutdownGracefully();<br \/>\n            workerGroup.shutdownGracefully();<br \/>\n        }<br \/>\n    }<br \/>\n} <\/p>\n<hr>\n<h3 id=\"%EF%BC%883%EF%BC%89IotServerInitializer.java%EF%BC%88Pipeline%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%89\">\uff083\uff09IotServerInitializer.java\uff08Pipeline\u521d\u59cb\u5316\uff09<\/h3>\n<p>public class IotServerInitializer extends ChannelInitializer&lt;SocketChannel&gt; {<br \/>\n    @Override<br \/>\n    protected void initChannel(SocketChannel ch) {<br \/>\n        ChannelPipeline pipeline = ch.pipeline();<br \/>\n        pipeline.addLast(new IotMessageDecoder());<br \/>\n        pipeline.addLast(new IotMessageEncoder());<br \/>\n        pipeline.addLast(new IotServerHandler());<br \/>\n    }<br \/>\n} <\/p>\n<h3 id=\"%EF%BC%885%EF%BC%89DeviceChannelManager.java%EF%BC%88%E8%AE%BE%E5%A4%87%E8%BF%9E%E6%8E%A5%E7%AE%A1%E7%90%86%E5%99%A8%EF%BC%89\">\uff084\uff09DeviceChannelManager.java\uff08\u8bbe\u5907\u8fde\u63a5\u7ba1\u7406\u5668\uff09<\/h3>\n<p>public class DeviceChannelManager {<br \/>\n    private static final Map&lt;String, Channel&gt; deviceChannels = new ConcurrentHashMap&lt;&gt;();<br \/>\n    public static void register(String deviceId, Channel channel) {<br \/>\n        deviceChannels.put(deviceId, channel);<br \/>\n    }<br \/>\n    public static void remove(Channel channel) {<br \/>\n        deviceChannels.values().removeIf(value -&gt; value.equals(channel));<br \/>\n    }<br \/>\n    public static Channel get(String deviceId) {<br \/>\n        return deviceChannels.get(deviceId);<br \/>\n    }<br \/>\n} <\/p>\n<hr>\n<h3 id=\"%EF%BC%884%EF%BC%89model%2FIotMessage.java%EF%BC%88%E6%B6%88%E6%81%AF%E5%AE%9E%E4%BD%93%EF%BC%89\">\uff085\uff09model\/IotMessage.java\uff08\u6d88\u606f\u5b9e\u4f53\uff09<\/h3>\n<p>public class IotMessage {<br \/>\n    private byte type;<br \/>\n    private String deviceId;<br \/>\n    private byte[] payload;<br \/>\n    \/\/ getter\u3001setter\u7701\u7565<br \/>\n} <\/p>\n<hr>\n<h3 id=\"%EF%BC%885%EF%BC%89IotMessageDecoder.java%EF%BC%88%E8%87%AA%E5%AE%9A%E4%B9%89%E8%A7%A3%E7%A0%81%E5%99%A8%EF%BC%89\">\uff086\uff09IotMessageDecoder.java\uff08\u81ea\u5b9a\u4e49\u89e3\u7801\u5668\uff09<\/h3>\n<p>public class IotMessageDecoder extends ByteToMessageDecoder {<br \/>\n    @Override<br \/>\n    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List&lt;Object&gt; out) {<br \/>\n        if (in.readableBytes() &lt; 10) return; \/\/ \u6700\u5c0f\u6d88\u606f\u957f\u5ea6\u68c0\u67e5<\/p>\n<p>        in.markReaderIndex();<br \/>\n        int header = in.readInt();<br \/>\n        byte type = in.readByte();<br \/>\n        byte deviceIdLength = in.readByte();<br \/>\n        int payloadLength = in.readInt();<br \/>\n        if (in.readableBytes(<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf13\u6b21\u3002Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357<\/p>\n","protected":false},"author":2,"featured_media":35089,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[220,2989],"topic":[],"class_list":["post-35090","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-220","tag-2989"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357 - \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\/35090.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf13\u6b21\u3002Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/35090.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-02T04:45:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250502044548-68144dfc17b0b.png\" \/>\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=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35090.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/35090.html\",\"name\":\"Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-02T04:45:52+00:00\",\"dateModified\":\"2025-05-02T04:45:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/35090.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/35090.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35090.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357\"}]},{\"@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":"Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357 - \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\/35090.html","og_locale":"zh_CN","og_type":"article","og_title":"Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf13\u6b21\u3002Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357","og_url":"https:\/\/www.wsisp.com\/helps\/35090.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-02T04:45:52+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250502044548-68144dfc17b0b.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/35090.html","url":"https:\/\/www.wsisp.com\/helps\/35090.html","name":"Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-02T04:45:52+00:00","dateModified":"2025-05-02T04:45:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/35090.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/35090.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/35090.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Netty\u9ad8\u5e76\u53d1\u7269\u8054\u7f51\u901a\u4fe1\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u4f18\u5316\u4e0e\u6027\u80fd\u8c03\u4f18\u6307\u5357"}]},{"@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\/35090","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=35090"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35090\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/35089"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=35090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=35090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=35090"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=35090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}