{"id":20375,"date":"2025-04-19T03:13:18","date_gmt":"2025-04-18T19:13:18","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/20375.html"},"modified":"2025-04-19T03:13:18","modified_gmt":"2025-04-18T19:13:18","slug":"express%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%80%9a%e8%bf%87mqtt%e8%bd%ac%e5%8f%91%e8%af%b7%e6%b1%82%e5%ae%9e%e7%8e%b0p2p%e5%a4%84%e7%90%86%e8%af%b7%e6%b1%82","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/20375.html","title":{"rendered":"Express\u670d\u52a1\u5668\u901a\u8fc7MQTT\u8f6c\u53d1\u8bf7\u6c42\u5b9e\u73b0P2P\u5904\u7406\u8bf7\u6c42"},"content":{"rendered":"<p>\u4f17\u6240\u5468\u77e5\uff0c\u5bf9\u4e8e\u4e2a\u4eba\u7528\u6237\u800c\u8a00\uff0c\u4e91\u670d\u52a1\u5668\u7684\u6027\u80fd\u5f80\u5f80\u4f34\u968f\u7740\u9ad8\u6602\u7684\u6210\u672c\u3002\u90a3\u4e48\uff0c\u5982\u4f55\u624d\u80fd\u4ee5\u66f4\u7ecf\u6d4e\u7684\u65b9\u5f0f\u83b7\u5f97\u9ad8\u6027\u80fd\u5e76\u786e\u4fdd\u62e5\u6709\u56fa\u5b9a\u7684\u516c\u7f51\u8bbf\u95ee\u5462\uff1f\u7b54\u6848\u5c31\u662f\u5229\u7528 P2P\uff08\u70b9\u5bf9\u70b9\uff09\u6280\u672f \u6765\u8f6c\u53d1\u6570\u636e\u3002<\/p>\n<p>\u901a\u8fc7 P2P \u7f51\u7edc\u67b6\u6784\uff0c\u6570\u636e\u53ef\u4ee5\u5728\u5404\u4e2a\u8282\u70b9\u4e4b\u95f4\u76f4\u63a5\u4f20\u8f93\uff0c\u800c\u65e0\u9700\u4f9d\u8d56\u6602\u8d35\u7684\u4e2d\u592e\u670d\u52a1\u5668\u3002\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u80fd\u591f\u663e\u8457\u964d\u4f4e\u8fd0\u8425\u6210\u672c\uff0c\u8fd8\u80fd\u5145\u5206\u5229\u7528\u7f51\u7edc\u4e2d\u5404\u4e2a\u8282\u70b9\u7684\u95f2\u7f6e\u8d44\u6e90\uff0c\u4ece\u800c\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\u6570\u636e\u4f20\u8f93\u3002\u6b64\u5916\uff0cP2P\u7f51\u7edc\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u53ef\u4ee5\u62e5\u6709\u56fa\u5b9a\u7684\u516c\u7f51\u5730\u5740\uff0c\u786e\u4fdd\u4e86\u7a33\u5b9a\u7684\u7f51\u7edc\u8fde\u63a5\u548c\u9ad8\u6548\u7684\u901a\u4fe1\u3002<\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4e2a\u4eba\u7528\u6237\u53ef\u4ee5\u5728\u4e0d\u727a\u7272\u6027\u80fd\u7684\u524d\u63d0\u4e0b\uff0c\u5927\u5e45\u964d\u4f4e\u5bf9\u4e91\u670d\u52a1\u5668\u7684\u4f9d\u8d56\uff0c\u5b9e\u73b0\u66f4\u7ecf\u6d4e\u3001\u9ad8\u6548\u7684\u7f51\u7edc\u89e3\u51b3\u65b9\u6848\u3002\u8fd9\u91cc\u91c7\u7528\u7684HTTP+MQTT\u7684\u65b9\u5f0f\uff0c\u9759\u6001\u8d44\u6e90\u53ef\u4ee5\u7559\u5b58\u670d\u52a1\u5668\uff0c\u800c\u9700\u8981\u8ba1\u7b97\u91cf\u7684API\u5219\u53ef\u4ee5\u901a\u8fc7\u57fa\u4e8eMQTT\u7684P2P\u8f6c\u53d1\u3002<\/p>\n<p>\u8981\u5b9e\u73b0\u4e00\u4e2a\u4f7f\u7528 Express \u4f5c\u4e3a\u516c\u7f51\u670d\u52a1\u5668\u63a5\u6536 HTTP \u8bf7\u6c42\uff0c\u5e76\u901a\u8fc7 MQTT \u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u5c40\u57df\u7f51\u5185\u7684\u9ad8\u6027\u80fd\u670d\u52a1\u5668\uff0c\u7b49\u5f85\u7ed3\u679c\u5e76\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u7684\u67b6\u6784\uff0c\u60a8\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u9700\u8981\u5904\u7406\u5f02\u6b65\u8bf7\u6c42\uff0c\u786e\u4fdd\u6bcf\u4e2a HTTP \u8bf7\u6c42\u90fd\u80fd\u7b49\u5f85 MQTT \u6d88\u606f\u7684\u54cd\u5e94\u3002<\/p>\n<h4>\u67b6\u6784\u6982\u8ff0<\/h4>\n<li>\n<p>Express \u670d\u52a1\u5668\uff08\u516c\u7f51\u670d\u52a1\u5668\uff09\uff1a<\/p>\n<ul>\n<li>\u63a5\u6536\u6765\u81ea\u5ba2\u6237\u7aef\u7684 HTTP \u8bf7\u6c42\u3002<\/li>\n<li>\u5c06\u8bf7\u6c42\u6570\u636e\u901a\u8fc7 MQTT \u53d1\u9001\u5230\u5c40\u57df\u7f51\u670d\u52a1\u5668\u3002<\/li>\n<li>\u7b49\u5f85\u6765\u81ea\u5c40\u57df\u7f51\u670d\u52a1\u5668\u7684 MQTT \u54cd\u5e94\u3002<\/li>\n<li>\u5c06\u54cd\u5e94\u6570\u636e\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5c40\u57df\u7f51\u9ad8\u6027\u80fd\u670d\u52a1\u5668\uff1a<\/p>\n<ul>\n<li>\u8ba2\u9605\u7279\u5b9a\u7684 MQTT \u4e3b\u9898\u3002<\/li>\n<li>\u5904\u7406\u6765\u81ea\u516c\u7f51\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u3002<\/li>\n<li>\u5c06\u5904\u7406\u7ed3\u679c\u901a\u8fc7 MQTT \u53d1\u9001\u56de\u516c\u7f51\u670d\u52a1\u5668\u3002<\/li>\n<\/ul>\n<\/li>\n<h4>\u6b65\u9aa4\u8be6\u89e3<\/h4>\n<h5>1. \u8bbe\u7f6e MQTT Broker<\/h5>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u4e00\u4e2a MQTT Broker \u6765\u4e2d\u8f6c\u6d88\u606f\u3002\u53ef\u4ee5\u4f7f\u7528 Mosquitto\u3001EMQX \u6216\u5176\u4ed6 MQTT Broker\u3002\u8fd9\u91cc\u4ee5 Mosquitto \u4e3a\u4f8b\uff1a<\/p>\n<p><span class=\"token comment\"># \u5b89\u88c5 Mosquitto\uff08\u4ee5 Ubuntu \u4e3a\u4f8b\uff09<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt-get<\/span> update<br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt-get<\/span> <span class=\"token function\">install<\/span> mosquitto mosquitto-clients<\/p>\n<p><span class=\"token comment\"># \u542f\u52a8 Mosquitto<\/span><br \/>\n<span class=\"token function\">sudo<\/span> systemctl start mosquitto<\/p>\n<h5>2. \u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56<\/h5>\n<p>\u5728\u60a8\u7684\u9879\u76ee\u4e2d\u5b89\u88c5 Express\u3001MQTT.js \u548c async\uff08\u7528\u4e8e\u5904\u7406\u5f02\u6b65\u6d41\u7a0b\uff09\uff1a<\/p>\n<p><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> express mqtt async<\/p>\n<h5>3. \u5b9e\u73b0\u516c\u7f51 Express \u670d\u52a1\u5668<\/h5>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u63a5\u6536 HTTP \u8bf7\u6c42\uff0c\u901a\u8fc7 MQTT \u8f6c\u53d1\u8bf7\u6c42\uff0c\u5e76\u7b49\u5f85\u54cd\u5e94\uff1a<\/p>\n<p><span class=\"token keyword\">const<\/span> express <span class=\"token operator\">=<\/span> <span class=\"token function\">require<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;express\\&#8217;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> mqtt <span class=\"token operator\">=<\/span> <span class=\"token function\">require<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;mqtt\\&#8217;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> async <span class=\"token operator\">=<\/span> <span class=\"token function\">require<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;async\\&#8217;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> uuid <span class=\"token operator\">=<\/span> <span class=\"token function\">require<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;uuid\\&#8217;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> app <span class=\"token operator\">=<\/span> <span class=\"token function\">express<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> port <span class=\"token operator\">=<\/span> <span class=\"token number\">3000<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ MQTT Broker \u8fde\u63a5\u914d\u7f6e<\/span><br \/>\n<span class=\"token keyword\">const<\/span> mqttHost <span class=\"token operator\">=<\/span> <span class=\"token string\">\\&#8217;mqtt:\/\/localhost\\&#8217;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u6839\u636e\u5b9e\u9645\u60c5\u51b5\u4fee\u6539<\/span><br \/>\n<span class=\"token keyword\">const<\/span> clientId <span class=\"token operator\">=<\/span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`<\/span><span class=\"token string\">express_<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<br \/>\n     <\/span>uuid<span class=\"token punctuation\">.<\/span><span class=\"token function\">v4<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token template-punctuation string\">`<\/span><\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">const<\/span> connectUrl <span class=\"token operator\">=<\/span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<br \/>\n     <\/span>mqttHost<span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token template-punctuation string\">`<\/span><\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> client <span class=\"token operator\">=<\/span> mqtt<span class=\"token punctuation\">.<\/span><span class=\"token function\">connect<\/span><span class=\"token punctuation\">(<\/span>connectUrl<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<br \/>\n   <\/span><br \/>\n    clientId<span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token literal-property property\">clean<\/span><span class=\"token operator\">:<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token literal-property property\">connectTimeout<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">4000<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token literal-property property\">reconnectPeriod<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">1000<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5b58\u50a8\u7b49\u5f85\u7684\u54cd\u5e94<\/span><br \/>\n<span class=\"token keyword\">const<\/span> responseMap <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">{<br \/>\n   <\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>client<span class=\"token punctuation\">.<\/span><span class=\"token function\">on<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;connect\\&#8217;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">=&gt;<\/span> <span class=\"token punctuation\">{<br \/>\n   <\/span><br \/>\n    console<span class=\"token punctuation\">.<\/span><span class=\"token function\">log<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;Connected to MQTT Broker\\&#8217;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u8ba2\u9605\u7528\u4e8e\u63a5\u6536\u54cd\u5e94\u7684\u4e3b\u9898<\/span><br \/>\n    client<span class=\"token punctuation\">.<\/span><span class=\"token function\">subscribe<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;response_topic\\&#8217;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">err<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">=&gt;<\/span> <span class=\"token punctuation\">{<br \/>\n   <\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span>err<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<br \/>\n   <\/span><br \/>\n            console<span class=\"token punctuation\">.<\/span><span class=\"token function\">log<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;Subscribed to response_topic\\&#8217;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5904\u7406\u6765\u81ea MQTT Broker \u7684\u54cd\u5e94<\/span><br \/>\nclient<span class=\"token punctuation\">.<\/span><span class=\"token function\">on<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;message\\&#8217;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">topic<span class=\"token punctuation\">,<\/span> message<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">=&gt;<\/span> <span class=\"token punctuation\">{<br \/>\n   <\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>topic <span class=\"token operator\">===<\/span> <span class=\"token string\">\\&#8217;response_topic\\&#8217;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<br \/>\n   <\/span><br \/>\n        <span class=\"token keyword\">const<\/span> payload <span class=\"token operator\">=<\/span> <span class=\"token constant\">JSON<\/span><span class=\"token punctuation\">.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb771\u6b21\uff0c\u70b9\u8d5e14\u6b21\uff0c\u6536\u85cf28\u6b21\u3002Express \u670d\u52a1\u5668\uff08\u516c\u7f51\u670d\u52a1\u5668\uff09\u63a5\u6536\u6765\u81ea\u5ba2\u6237\u7aef\u7684HTTP\u8bf7\u6c42\u3002\u5c06\u8bf7\u6c42\u6570\u636e\u901a\u8fc7MQTT\u53d1\u9001\u5230\u5c40\u57df\u7f51\u670d\u52a1\u5668\u3002\u7b49\u5f85\u6765\u81ea\u5c40\u57df\u7f51\u670d\u52a1\u5668\u7684MQTT\u54cd\u5e94\u3002\u5c06\u54cd\u5e94\u6570\u636e\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u5c40\u57df\u7f51\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u8ba2\u9605\u7279\u5b9a\u7684MQTT\u4e3b\u9898\u3002\u5904\u7406\u6765\u81ea\u516c\u7f51\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u3002\u5c06\u5904\u7406\u7ed3\u679c\u901a\u8fc7MQTT\u53d1\u9001\u56de\u516c\u7f51\u670d\u52a1\u5668\u3002\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2aExpress\u670d\u52a1\u5668\u63a5\u6536HTTP\u8bf7\u6c42\uff0c\u5e76\u901a\u8fc7MQTT\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u5c40\u57df\u7f51\u670d\u52a1\u5668\uff0c\u7b49\u5f85\u54cd\u5e94\u540e\u518d\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u5173\u952e\u5728\u4e8e\u4f7f\u7528MQTT\u7684\u6a21\u5f0f\uff0c\u4ee5\u53ca\u5728Express\u4e2d\u7ba1\u7406\u5f02\u6b65\u8bf7\u6c42\u7684\u56de\u8c03\u548c\u8d85\u65f6\u5904\u7406\u3002_express mqtt<\/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":[709,1249,43],"topic":[],"class_list":["post-20375","post","type-post","status-publish","format-standard","hentry","category-server","tag-express","tag-p2p","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Express\u670d\u52a1\u5668\u901a\u8fc7MQTT\u8f6c\u53d1\u8bf7\u6c42\u5b9e\u73b0P2P\u5904\u7406\u8bf7\u6c42 - \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\/20375.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Express\u670d\u52a1\u5668\u901a\u8fc7MQTT\u8f6c\u53d1\u8bf7\u6c42\u5b9e\u73b0P2P\u5904\u7406\u8bf7\u6c42 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb771\u6b21\uff0c\u70b9\u8d5e14\u6b21\uff0c\u6536\u85cf28\u6b21\u3002Express \u670d\u52a1\u5668\uff08\u516c\u7f51\u670d\u52a1\u5668\uff09\u63a5\u6536\u6765\u81ea\u5ba2\u6237\u7aef\u7684HTTP\u8bf7\u6c42\u3002\u5c06\u8bf7\u6c42\u6570\u636e\u901a\u8fc7MQTT\u53d1\u9001\u5230\u5c40\u57df\u7f51\u670d\u52a1\u5668\u3002\u7b49\u5f85\u6765\u81ea\u5c40\u57df\u7f51\u670d\u52a1\u5668\u7684MQTT\u54cd\u5e94\u3002\u5c06\u54cd\u5e94\u6570\u636e\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u5c40\u57df\u7f51\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u8ba2\u9605\u7279\u5b9a\u7684MQTT\u4e3b\u9898\u3002\u5904\u7406\u6765\u81ea\u516c\u7f51\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u3002\u5c06\u5904\u7406\u7ed3\u679c\u901a\u8fc7MQTT\u53d1\u9001\u56de\u516c\u7f51\u670d\u52a1\u5668\u3002\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2aExpress\u670d\u52a1\u5668\u63a5\u6536HTTP\u8bf7\u6c42\uff0c\u5e76\u901a\u8fc7MQTT\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u5c40\u57df\u7f51\u670d\u52a1\u5668\uff0c\u7b49\u5f85\u54cd\u5e94\u540e\u518d\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u5173\u952e\u5728\u4e8e\u4f7f\u7528MQTT\u7684\u6a21\u5f0f\uff0c\u4ee5\u53ca\u5728Express\u4e2d\u7ba1\u7406\u5f02\u6b65\u8bf7\u6c42\u7684\u56de\u8c03\u548c\u8d85\u65f6\u5904\u7406\u3002_express mqtt\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/20375.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T19:13:18+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=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/20375.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/20375.html\",\"name\":\"Express\u670d\u52a1\u5668\u901a\u8fc7MQTT\u8f6c\u53d1\u8bf7\u6c42\u5b9e\u73b0P2P\u5904\u7406\u8bf7\u6c42 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T19:13:18+00:00\",\"dateModified\":\"2025-04-18T19:13:18+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/20375.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/20375.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/20375.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Express\u670d\u52a1\u5668\u901a\u8fc7MQTT\u8f6c\u53d1\u8bf7\u6c42\u5b9e\u73b0P2P\u5904\u7406\u8bf7\u6c42\"}]},{\"@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":"Express\u670d\u52a1\u5668\u901a\u8fc7MQTT\u8f6c\u53d1\u8bf7\u6c42\u5b9e\u73b0P2P\u5904\u7406\u8bf7\u6c42 - \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\/20375.html","og_locale":"zh_CN","og_type":"article","og_title":"Express\u670d\u52a1\u5668\u901a\u8fc7MQTT\u8f6c\u53d1\u8bf7\u6c42\u5b9e\u73b0P2P\u5904\u7406\u8bf7\u6c42 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb771\u6b21\uff0c\u70b9\u8d5e14\u6b21\uff0c\u6536\u85cf28\u6b21\u3002Express \u670d\u52a1\u5668\uff08\u516c\u7f51\u670d\u52a1\u5668\uff09\u63a5\u6536\u6765\u81ea\u5ba2\u6237\u7aef\u7684HTTP\u8bf7\u6c42\u3002\u5c06\u8bf7\u6c42\u6570\u636e\u901a\u8fc7MQTT\u53d1\u9001\u5230\u5c40\u57df\u7f51\u670d\u52a1\u5668\u3002\u7b49\u5f85\u6765\u81ea\u5c40\u57df\u7f51\u670d\u52a1\u5668\u7684MQTT\u54cd\u5e94\u3002\u5c06\u54cd\u5e94\u6570\u636e\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u5c40\u57df\u7f51\u9ad8\u6027\u80fd\u670d\u52a1\u5668\u8ba2\u9605\u7279\u5b9a\u7684MQTT\u4e3b\u9898\u3002\u5904\u7406\u6765\u81ea\u516c\u7f51\u670d\u52a1\u5668\u7684\u8bf7\u6c42\u3002\u5c06\u5904\u7406\u7ed3\u679c\u901a\u8fc7MQTT\u53d1\u9001\u56de\u516c\u7f51\u670d\u52a1\u5668\u3002\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2aExpress\u670d\u52a1\u5668\u63a5\u6536HTTP\u8bf7\u6c42\uff0c\u5e76\u901a\u8fc7MQTT\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u5c40\u57df\u7f51\u670d\u52a1\u5668\uff0c\u7b49\u5f85\u54cd\u5e94\u540e\u518d\u8fd4\u56de\u7ed9\u5ba2\u6237\u7aef\u3002\u5173\u952e\u5728\u4e8e\u4f7f\u7528MQTT\u7684\u6a21\u5f0f\uff0c\u4ee5\u53ca\u5728Express\u4e2d\u7ba1\u7406\u5f02\u6b65\u8bf7\u6c42\u7684\u56de\u8c03\u548c\u8d85\u65f6\u5904\u7406\u3002_express mqtt","og_url":"https:\/\/www.wsisp.com\/helps\/20375.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T19:13:18+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/20375.html","url":"https:\/\/www.wsisp.com\/helps\/20375.html","name":"Express\u670d\u52a1\u5668\u901a\u8fc7MQTT\u8f6c\u53d1\u8bf7\u6c42\u5b9e\u73b0P2P\u5904\u7406\u8bf7\u6c42 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T19:13:18+00:00","dateModified":"2025-04-18T19:13:18+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/20375.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/20375.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/20375.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Express\u670d\u52a1\u5668\u901a\u8fc7MQTT\u8f6c\u53d1\u8bf7\u6c42\u5b9e\u73b0P2P\u5904\u7406\u8bf7\u6c42"}]},{"@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\/20375","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=20375"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/20375\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=20375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=20375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=20375"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=20375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}