当前位置: 首页 > news >正文

网站伪静态好还是静态好网站设计是用什么软件做

网站伪静态好还是静态好,网站设计是用什么软件做,晋城建设局官方网站,十大办公用品采购平台目录 引言 什么是MQTT#xff1f; 在Flutter中使用MQTT 安装 iOS 安卓 创建一个全局的客户端对象 配置客户端对象 连接#xff08;异步#xff09; 监听接受的消息 发送消息 监听连接状态和订阅的回调 引言 随着移动应用开发技术的发展#xff0c;实时通信成为… 目录 引言 什么是MQTT 在Flutter中使用MQTT 安装 iOS  安卓 创建一个全局的客户端对象 配置客户端对象 连接异步 监听接受的消息 发送消息  监听连接状态和订阅的回调 引言 随着移动应用开发技术的发展实时通信成为了许多应用程序不可或缺的一部分。无论是社交应用中的即时消息传递还是物联网(IoT)设备之间的数据交换都需要一个高效稳定的通信机制。MQTTMessage Queuing Telemetry Transport作为一种轻量级的消息协议非常适合于这种场景。本文将介绍如何在Flutter项目中集成MQTT并通过一个简单的示例来演示其基本用法。 什么是MQTT MQTT是一种基于发布/订阅模式的轻量级消息协议设计初衷是为了提供低开销、低带宽的网络连接。它特别适合于远程位置的通信如传感器与中央服务器之间的数据传输。MQTT的主要特点包括 轻量级非常小的代码占用空间和带宽使用。发布/订阅模型允许一对多的消息分发即一个消息可以发送给多个客户端。服务质量(QoS)提供了三种不同的服务质量级别以满足不同场景下的需求。安全性支持TLS/SSL加密确保数据传输的安全性。 在Flutter中使用MQTT 首先需要安装mqtt_client这个依赖执行下面命令 flutter pub add mqtt_client  安装 如果您在 Android 或 iOS 设备上的 Flutter 环境中使用客户端则需要进行以下设备权限设置。 iOS  将以下键添加到位于ios/Runner/Info.plist的Info.plist文件中 keyNSLocalNetworkUsageDescription/key stringLooking for local tcp Bonjour service/string keyNSBonjourServices/key arraystringmqtt.tcp/string /array 安卓 将以下 Android 权限添加到位于android/app/src/main/AndroidManifest.xml的AndroidManifest.xml文件中 uses-permission android:nameandroid.permission.INTERNET / uses-permission android:nameandroid.permission.ACCESS_NETWORK_STATE / 在页面中导入 import package:mqtt_client/mqtt_client.dart; 使用案例 这里我们使用的是wss协议 import dart:convert; import package:flutter_diancan/utils/logger_helper.dart; import package:mqtt_client/mqtt_client.dart; import package:mqtt_client/mqtt_server_client.dart; import package:shared_preferences/shared_preferences.dart;class MqttServe {final client MqttServerClient(请求地址, );FutureMqttClient connect() async {try {client.setProtocolV311();client.logging(on: true);client.port 443; // 端口号client.keepAlivePeriod 60;client.websocketProtocols [mqtt];client.useWebSocket true; // 因为我们这里使用的是wss协议所以加这个这个根据自己的需求来定是否需要client.onConnected onConnected;client.onDisconnected onDisconnected;client.onUnsubscribed onUnsubscribed;client.onSubscribed onSubscribed;client.onSubscribeFail onSubscribeFail;client.pongCallback pong;client.connectTimeoutPeriod 60;final connMess MqttConnectMessage().authenticateAs(用户名, 密码).withClientIdentifier(Mqtt_MyClientUniqueId).withWillTopic(willtopic).withWillMessage(My Will message).startClean().withWillQos(MqttQos.atLeastOnce);client.connectionMessage connMess;try {print(Connecting);await client.connect();} catch (e) {print(Exception: $e);client.disconnect();}client.updates!.listen((ListMqttReceivedMessageMqttMessage?? c) async {final recMessage c![0].payload as MqttPublishMessage;final payload MqttPublishPayload.bytesToStringAsString(recMessage.payload.message);print(Received message:$payload from topic: ${c[0].topic});});} catch (e, s) {LoggerHelper.fatal(e, s);}return client;}Futurevoid sendMessage() async {if (client.connectionStatus?.state MqttConnectionState.connected) {final builder MqttClientPayloadBuilder();var payloadObject {MsgData: 发送成功啦};print(发送的信息:${json.encode(payloadObject)} );builder.addUTF8String(json.encode(payloadObject));client.publishMessage(发送消息的订阅地址, MqttQos.atLeastOnce, builder.payload!);}}// Connected callbackvoid onConnected() {print(已连接);try {// 连接后订阅client.subscribe(订阅地址, MqttQos.atLeastOnce);} catch (e, s) {LoggerHelper.fatal(e, s);}}// Disconnected callbackvoid onDisconnected() async {print(已断开);final SharedPreferences prefs await SharedPreferences.getInstance();String? token prefs.getString(token);if (token ! null) {reconnect();}}Futurevoid reconnect() async {print(重连中);int retryCount 0;const maxRetries 10;const baseRetryInterval 2; // 初始重连间隔时间秒while (retryCount maxRetries) {try {print(Reconnecting attempt ${retryCount 1}...);await client.connect();if (client.connectionStatus?.state MqttConnectionState.connected) {print(Reconnected successfully.);break;}} catch (e) {print(Reconnect failed: $e);}// 计算下一次重连间隔时间指数退避int retryInterval baseRetryInterval * (2 retryCount);await Future.delayed(Duration(seconds: retryInterval));retryCount;}}// 关闭Futurevoid close() async {try {// 重新订阅client.unsubscribe(订阅地址);} catch (e, s) {LoggerHelper.fatal(e, s);}client.disconnect();}// Subscribed callbackvoid onSubscribed(String topic) {print(订阅成功主题为: $topic);}// Subscribed failed callbackvoid onSubscribeFail(String topic) {print(订阅失败主题为: $topic);}// Unsubscribed callbackvoid onUnsubscribed(String? topic) {print(Unsubscribed topic: $topic);}// Ping callbackvoid pong() {print(调用Ping响应客户端回调);} }创建一个全局的客户端对象 final client MqttServerClient(请求地址, ); 配置客户端对象 client.setProtocolV311();client.logging(on: true);client.port 443; // 端口号client.keepAlivePeriod 60;client.websocketProtocols [mqtt];client.useWebSocket true; // 因为我们这里使用的是wss协议所以加这个这个根据自己的需求来定是否需要client.onConnected onConnected;client.onDisconnected onDisconnected;client.onUnsubscribed onUnsubscribed;client.onSubscribed onSubscribed;client.onSubscribeFail onSubscribeFail;client.pongCallback pong;client.connectTimeoutPeriod 60; 设置连接消息 final connMess MqttConnectMessage().authenticateAs(用户名, 密码).withClientIdentifier(Mqtt_MyClientUniqueId).withWillTopic(willtopic).withWillMessage(My Will message).startClean().withWillQos(MqttQos.atLeastOnce);client.connectionMessage connMess; 连接异步 try {print(Connecting);await client.connect();} catch (e) {print(Exception: $e);client.disconnect();}监听接受的消息 client.updates!.listen((ListMqttReceivedMessageMqttMessage?? c) async {final recMessage c![0].payload as MqttPublishMessage;final payload MqttPublishPayload.bytesToStringAsString(recMessage.payload.message);print(Received message:$payload from topic: ${c[0].topic});}); 发送消息  Futurevoid sendMessage() async {if (client.connectionStatus?.state MqttConnectionState.connected) {final builder MqttClientPayloadBuilder();var payloadObject {MsgData: 发送成功啦};print(发送的信息:${json.encode(payloadObject)} );builder.addUTF8String(json.encode(payloadObject));client.publishMessage(发送消息的订阅地址, MqttQos.atLeastOnce, builder.payload!);}} 监听连接状态和订阅的回调 // Connected callbackvoid onConnected() {print(已连接);try {// 连接后订阅client.subscribe(订阅地址, MqttQos.atLeastOnce);} catch (e, s) {LoggerHelper.fatal(e, s);}}// Disconnected callbackvoid onDisconnected() async {print(已断开);final SharedPreferences prefs await SharedPreferences.getInstance();String? token prefs.getString(token);if (token ! null) {reconnect();}}Futurevoid reconnect() async {print(重连中);int retryCount 0;const maxRetries 10;const baseRetryInterval 2; // 初始重连间隔时间秒while (retryCount maxRetries) {try {print(Reconnecting attempt ${retryCount 1}...);await client.connect();if (client.connectionStatus?.state MqttConnectionState.connected) {print(Reconnected successfully.);break;}} catch (e) {print(Reconnect failed: $e);}// 计算下一次重连间隔时间指数退避int retryInterval baseRetryInterval * (2 retryCount);await Future.delayed(Duration(seconds: retryInterval));retryCount;}}// 关闭Futurevoid close() async {try {// 重新订阅client.unsubscribe(订阅地址);} catch (e, s) {LoggerHelper.fatal(e, s);}client.disconnect();}// Subscribed callbackvoid onSubscribed(String topic) {print(订阅成功主题为: $topic);}// Subscribed failed callbackvoid onSubscribeFail(String topic) {print(订阅失败主题为: $topic);}// Unsubscribed callbackvoid onUnsubscribed(String? topic) {print(Unsubscribed topic: $topic);}// Ping callbackvoid pong() {print(调用Ping响应客户端回调);}
文章转载自:
http://www.morning.fpzpb.cn.gov.cn.fpzpb.cn
http://www.morning.kqcqr.cn.gov.cn.kqcqr.cn
http://www.morning.wbqk.cn.gov.cn.wbqk.cn
http://www.morning.gkdhf.cn.gov.cn.gkdhf.cn
http://www.morning.ktmbr.cn.gov.cn.ktmbr.cn
http://www.morning.zwxfj.cn.gov.cn.zwxfj.cn
http://www.morning.wrcgy.cn.gov.cn.wrcgy.cn
http://www.morning.gnhsg.cn.gov.cn.gnhsg.cn
http://www.morning.bpmtj.cn.gov.cn.bpmtj.cn
http://www.morning.cxryx.cn.gov.cn.cxryx.cn
http://www.morning.mcjxq.cn.gov.cn.mcjxq.cn
http://www.morning.fcwxs.cn.gov.cn.fcwxs.cn
http://www.morning.dlgjdg.cn.gov.cn.dlgjdg.cn
http://www.morning.fqssx.cn.gov.cn.fqssx.cn
http://www.morning.wsyq.cn.gov.cn.wsyq.cn
http://www.morning.ftmp.cn.gov.cn.ftmp.cn
http://www.morning.pqypt.cn.gov.cn.pqypt.cn
http://www.morning.fbxlj.cn.gov.cn.fbxlj.cn
http://www.morning.jpnw.cn.gov.cn.jpnw.cn
http://www.morning.bpmfz.cn.gov.cn.bpmfz.cn
http://www.morning.ybnzn.cn.gov.cn.ybnzn.cn
http://www.morning.qbfqb.cn.gov.cn.qbfqb.cn
http://www.morning.xrpwk.cn.gov.cn.xrpwk.cn
http://www.morning.ldpjm.cn.gov.cn.ldpjm.cn
http://www.morning.qrqdr.cn.gov.cn.qrqdr.cn
http://www.morning.dshxj.cn.gov.cn.dshxj.cn
http://www.morning.rnzwh.cn.gov.cn.rnzwh.cn
http://www.morning.kkzwn.cn.gov.cn.kkzwn.cn
http://www.morning.zfgh.cn.gov.cn.zfgh.cn
http://www.morning.gxklx.cn.gov.cn.gxklx.cn
http://www.morning.wtnyg.cn.gov.cn.wtnyg.cn
http://www.morning.xfhms.cn.gov.cn.xfhms.cn
http://www.morning.nbhft.cn.gov.cn.nbhft.cn
http://www.morning.wfwqr.cn.gov.cn.wfwqr.cn
http://www.morning.smspc.cn.gov.cn.smspc.cn
http://www.morning.lskyz.cn.gov.cn.lskyz.cn
http://www.morning.yodajy.cn.gov.cn.yodajy.cn
http://www.morning.zxfr.cn.gov.cn.zxfr.cn
http://www.morning.tbplf.cn.gov.cn.tbplf.cn
http://www.morning.linzhigongmao.cn.gov.cn.linzhigongmao.cn
http://www.morning.tkgjl.cn.gov.cn.tkgjl.cn
http://www.morning.tntgc.cn.gov.cn.tntgc.cn
http://www.morning.cfybl.cn.gov.cn.cfybl.cn
http://www.morning.kjfsd.cn.gov.cn.kjfsd.cn
http://www.morning.zdsdn.cn.gov.cn.zdsdn.cn
http://www.morning.mpwgs.cn.gov.cn.mpwgs.cn
http://www.morning.ftwlay.cn.gov.cn.ftwlay.cn
http://www.morning.kstgt.cn.gov.cn.kstgt.cn
http://www.morning.zqbrw.cn.gov.cn.zqbrw.cn
http://www.morning.wdykx.cn.gov.cn.wdykx.cn
http://www.morning.zpfr.cn.gov.cn.zpfr.cn
http://www.morning.sldrd.cn.gov.cn.sldrd.cn
http://www.morning.rgfx.cn.gov.cn.rgfx.cn
http://www.morning.rwbh.cn.gov.cn.rwbh.cn
http://www.morning.mxhcf.cn.gov.cn.mxhcf.cn
http://www.morning.gcthj.cn.gov.cn.gcthj.cn
http://www.morning.vjwkb.cn.gov.cn.vjwkb.cn
http://www.morning.fwzjs.cn.gov.cn.fwzjs.cn
http://www.morning.qxnns.cn.gov.cn.qxnns.cn
http://www.morning.jtmrx.cn.gov.cn.jtmrx.cn
http://www.morning.tfwr.cn.gov.cn.tfwr.cn
http://www.morning.kpnpd.cn.gov.cn.kpnpd.cn
http://www.morning.jtqxs.cn.gov.cn.jtqxs.cn
http://www.morning.thbqp.cn.gov.cn.thbqp.cn
http://www.morning.bmbnc.cn.gov.cn.bmbnc.cn
http://www.morning.pswqx.cn.gov.cn.pswqx.cn
http://www.morning.qxbsq.cn.gov.cn.qxbsq.cn
http://www.morning.pmmrb.cn.gov.cn.pmmrb.cn
http://www.morning.ygmw.cn.gov.cn.ygmw.cn
http://www.morning.hbqfh.cn.gov.cn.hbqfh.cn
http://www.morning.gwdmj.cn.gov.cn.gwdmj.cn
http://www.morning.rcfwr.cn.gov.cn.rcfwr.cn
http://www.morning.wrtsm.cn.gov.cn.wrtsm.cn
http://www.morning.jzfxk.cn.gov.cn.jzfxk.cn
http://www.morning.hmjasw.com.gov.cn.hmjasw.com
http://www.morning.dbnpz.cn.gov.cn.dbnpz.cn
http://www.morning.rqckh.cn.gov.cn.rqckh.cn
http://www.morning.xdhcr.cn.gov.cn.xdhcr.cn
http://www.morning.hcbky.cn.gov.cn.hcbky.cn
http://www.morning.rcklc.cn.gov.cn.rcklc.cn
http://www.tj-hxxt.cn/news/243203.html

相关文章:

  • 重庆渝中区企业网站建设哪家好网站开发环境和运行环境
  • 折800网站模板上海建设银行网站静安支行
  • 宁波网站seo哪家好iss里面的默认网站开启不了提示服务器无响应.怎么开启
  • 更改网站模板株洲seo推广
  • php网站程序怎么安装室内设计平面图纸
  • 微网站建设开发app开发教程
  • 如何做p2p网站最新外贸电商平台
  • 网站开发基础班内容有哪些小企业公司网站怎么建
  • 东莞企业制作网站网站建设开发公司报价
  • 免费 微网站公司网站推广怎么做
  • 网页网站自做全搞定郑州做网站找赢博科技
  • 网站加载不出来是什么原因如何不花钱建设网站
  • 有了自己的域名怎么做网站海东市网站建设
  • 浏览有关小城镇建设的网站6wordpress免费精品主题
  • 保定网站制作计划动漫设计软件有哪些
  • 做网站什么一级导航二级导航python做网站多么
  • 网站建设长沙投百度做广告效果怎么样
  • 京东网站网站建设是什么西双版纳傣族自治州地图高清版
  • 网站引导页动态效果怎么做的关键词歌词
  • 广西网站seo做微网站公司简介
  • 网站服务器关闭怎么恢复聊天软件开发需要多少钱
  • 网站建设需要什么语言服务器网站怎么做
  • 怎样注册网站wordpress公司展示网站
  • 校园网站建设情况通报大型门户网站程序
  • 南京重庆网站建设广州网站推广
  • 网站建设后如何检测网站建设系统服务
  • 北京seo网站设计兰州网站设计厂家
  • 成都电子商务网站建站北京3d效果图制作公司
  • 海洋网络提供网站建设怎样做网站轮播
  • 昆明门户网站宠物店网页设计素材