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

上海崇明林业建设有限公司网站宁波建筑公司有哪些

上海崇明林业建设有限公司网站,宁波建筑公司有哪些,ipv6改造 网站怎么做6,园区做网站主要参考C#MQTT编程06--MQTT服务器和客户端(winform版)_c#mqttserver-CSDN博客 但由于使用的.NET版本和MQTT库版本存在差异#xff0c;因此有些不同。 MQTT协议内容在此不做描述#xff0c;仅介绍VS使用C#的实现过程。本次使用VS2015#xff0c;.netframwork4.6。 C#语言本身… 主要参考C#MQTT编程06--MQTT服务器和客户端(winform版)_c#mqttserver-CSDN博客 但由于使用的.NET版本和MQTT库版本存在差异因此有些不同。 MQTT协议内容在此不做描述仅介绍VS使用C#的实现过程。本次使用VS2015.netframwork4.6。 C#语言本身没有MQTT的库当然你也可以利用TCP自行完成MQTT协议实现一般我们采用第三方的mqtt库。 新建一个winform项目在解决方案资源管理器的“引用”右键选择“管理Nuget程序包”找到下面两个包并安装。注意我这里用的版本是V3.0.0。 接下来根据需要绘制窗体添加控件。这里有两个按钮一个连接MQTT服务器一个是断开然后就是订阅和发布相关的输入框和按钮。除此以外我这边需要测试发布几条指令做到下方的按钮里了省的手动输入。 接下来是代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Runtime; using System.Windows.Forms; using System.Threading.Tasks;using MQTTnet.Protocol; using MQTTnet.Client; using MQTTnet.Client.Options; using MQTTnet.Extensions.ManagedClient; using MQTTnet;namespace MQTT {public partial class Form1: Form{private IManagedMqttClient mqttClient;private bool conFlag false;private int timeout 0;public Form1(){InitializeComponent();}private async void button1_Click(object sender, EventArgs e){var mqttclientOptions new MqttClientOptionsBuilder().WithClientId(mushike).WithTcpServer(39.105.165.228, 1883).WithCredentials(admin, admin);var options new ManagedMqttClientOptionsBuilder().WithAutoReconnectDelay(TimeSpan.FromSeconds(5)).WithClientOptions(mqttclientOptions.Build()).Build();//开启await mqttClient.StartAsync(options);timer1.Enabled true;timeout 0;}private async void button2_Click(object sender, EventArgs e){if (mqttClient ! null){if (mqttClient.IsStarted){await mqttClient.StopAsync();}timer1.Enabled false;button1.BackColor SystemColors.Control;}}private void Form1_Load(object sender, EventArgs e){var factory new MqttFactory();mqttClient factory.CreateManagedMqttClient();//创建客户端对象//绑定断开事件mqttClient.UseDisconnectedHandler(async ee { // 等待 5s 时间await Task.Delay(TimeSpan.FromMilliseconds(500));WriteLog(\r\n与服务器之间的连接断开);conFlag false;});//绑定接收事件mqttClient.UseApplicationMessageReceivedHandler(aa {try{string msg aa.ApplicationMessage.ConvertPayloadToString();WriteLog(\r\n 收到主题 aa.ApplicationMessage.Topic \r\n内容为 msg);//WriteLog( 消息 msg QoS aa.ApplicationMessage.QualityOfServiceLevel 客户端 aa.ClientId 主题 aa.ApplicationMessage.Topic);}catch (Exception ex){WriteLog($\r\n 消息 ex.Message);}});//绑定连接事件mqttClient.UseConnectedHandler(ee {WriteLog(\r\n 连接到服务器成功);conFlag true;});}private void WriteLog(string message){if(textBox1.InvokeRequired){textBox1.Invoke(new Action(() {textBox1.AppendText(message);}));}else{textBox1.AppendText(message);}}private void button3_Click(object sender, EventArgs e){if (conFlag false)return;string topic textBox2.Text;string message textBox3.Text;mqtt_publish(topic, message);}private async void button4_Click(object sender, EventArgs e){if (conFlag false)return;string topic textBox4.Text;if (string.IsNullOrWhiteSpace(topic)){WriteLog(\r\n 请输入主题);return;}await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(topic).WithAtMostOnceQoS().Build());//最多一次 QoS 级别0WriteLog($\r\n 成功订阅);}private async void mqtt_publish(string topic,string message){if (conFlag false)return;if (string.IsNullOrWhiteSpace(topic)){WriteLog(\r\n 请输入主题);return;}var result await mqttClient.PublishAsync(topic,message,MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce);//恰好一次 QoS 级别1 WriteLog($\r\n 主题{topic}\r\n消息{message}\r\n结果 {result.ReasonCode});}private void textBox1_MouseDoubleClick(object sender, MouseEventArgs e){this.textBox1.Text ;}private void timer1_Tick(object sender, EventArgs e){timeout;if (conFlag true){button1.BackColor Color.Green;timer1.Enabled false;}else{if (timeout 30){timeout 0;timer1.Enabled false;WriteLog(\r\n 连接服务器失败);}}}private void button11_Click(object sender, EventArgs e){string topic test111;string message #01R00\r;mqtt_publish(topic, message);}private void button10_Click(object sender, EventArgs e){string topic test111;string message #01R01\r;mqtt_publish(topic, message);}private void button5_MouseDown(object sender, MouseEventArgs e){string topic test333;string message F10209100000000100000000E4;mqtt_publish(topic, message);}private void button5_MouseUp(object sender, MouseEventArgs e){string topic test333;string message F10209100000000000000000E5;mqtt_publish(topic, message);}private void button6_MouseDown(object sender, MouseEventArgs e){string topic test333;string message F10209100000000200000000E3;mqtt_publish(topic, message);}private void button6_MouseUp(object sender, MouseEventArgs e){string topic test333;string message F10209100000000000000000E5;mqtt_publish(topic, message);}private void button8_MouseDown(object sender, MouseEventArgs e){string topic test333;string message F10209100000000000020000E3;mqtt_publish(topic, message);}private void button8_MouseUp(object sender, MouseEventArgs e){string topic test333;string message F10209100000000000000000E5;mqtt_publish(topic, message);}private void button7_MouseDown(object sender, MouseEventArgs e){string topic test333;string message F10209100000000000040000E1;mqtt_publish(topic, message);}private void button7_MouseUp(object sender, MouseEventArgs e){string topic test333;string message F10209100000000000000000E5;mqtt_publish(topic, message);}private void button9_MouseDown(object sender, MouseEventArgs e){string topic test333;string message F10209100000000020000000C5;mqtt_publish(topic, message);}private void button9_MouseUp(object sender, MouseEventArgs e){string topic test333;string message F10209100000000000000000E5;mqtt_publish(topic, message);}} }本次参照 C#MQTT编程06--MQTT服务器和客户端(winform版)_c#mqttserver-CSDN博客 编写MQTT相关的代码时报了一堆错本质原因还是版本不一致导致比如使用参考博客的MQTTNet V3.0.15就用不了。因此需要特别注意本次使用的环境为VS2015.Net 4.6MQTTNet V3.0.0。
http://www.pierceye.com/news/314909/

相关文章:

  • 卫计网站建设工作总结铜陵建设行业培训学校网站
  • 手机网站竞价网页界面设计遵循的原则
  • 徐州seo推广公司广州营销型网站优化
  • 小说网站首页模板安徽华力建设集团网站
  • 减肥网站如何做公司企业模板
  • 郑州网站建设搜q.479185700怎么在百度上推广自己的公司信息
  • 深圳住建设局官方网站大连在哪个省市
  • 吉林企业建站系统费用wordpress幻灯片加载很慢
  • com域名和网站小型企业网站排名前十
  • 网站内容 优化泉州网站开发公司
  • 假发外贸网站模板做图库网站需要多少钱
  • 网站建设公司 知道万维科技wordpress支持移动
  • 经典网站建设邢台网站建设策划
  • 系统数据库与建设网站网站提交入口大全
  • 网站做数据分析的意义西安网站建设kxccc
  • 免费建个人网站alexa排名搜索
  • 做的网站第二年续费多钱店铺装修模板
  • 这么自己建设网站中卫网站设计厂家
  • 公司网站制作哪家公司好广州建设执业资格注册中心网站
  • 北京所有做招聘类网站建站公司Apache Wordpress伪静态处理
  • 大兴做网站公司制作网页可以用什么软件
  • 该怎么给做网站的提页面需求网上购物平台怎么建立
  • 用pw后缀的网站阳江网络问政平台首页
  • 建站网站建设哪个好网页设计个人总结
  • 网站开发时间进度表宁波网站建设使用技巧分享
  • wordpress官网案例移动端优化
  • 广告投放网宁波seo网络推广报价
  • 网站模板 哪个好烟台高端网站建设公司
  • 福建网站开发手机软件app下载
  • 网站开发的功能需求怎么写网页版式设计分析