C#使用MQTT(二):MQTT客户端

news2024/11/15 23:32:25

上一篇我们初步设计了MQTT服务端

C#使用MQTT(一):MQTT服务端-CSDN博客

这里我们设计客户端MQTT Client,接上一篇

新建Windows窗体FormMqttClient

窗体FormMqttClient设计如图:

窗体FormMqttClient设计器相关代码如下

文件FormMqttClient.Designer.cs


namespace CultureDemo
{
    partial class FormMqttClient
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.rtxtMessage = new System.Windows.Forms.RichTextBox();
            this.label8 = new System.Windows.Forms.Label();
            this.btnPublish = new System.Windows.Forms.Button();
            this.btnSubscribe = new System.Windows.Forms.Button();
            this.txtContent = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.txtTopicPublish = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.txtTopic = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.btnDisconnect = new System.Windows.Forms.Button();
            this.btnConnect = new System.Windows.Forms.Button();
            this.txtClientId = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.txtUpwd = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.txtUserName = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.txtPort = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.txtIP = new System.Windows.Forms.TextBox();
            this.lb = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // rtxtMessage
            // 
            this.rtxtMessage.Location = new System.Drawing.Point(239, 37);
            this.rtxtMessage.Name = "rtxtMessage";
            this.rtxtMessage.Size = new System.Drawing.Size(623, 411);
            this.rtxtMessage.TabIndex = 51;
            this.rtxtMessage.Text = "";
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(242, 18);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(29, 12);
            this.label8.TabIndex = 50;
            this.label8.Text = "消息";
            // 
            // btnPublish
            // 
            this.btnPublish.Location = new System.Drawing.Point(117, 425);
            this.btnPublish.Name = "btnPublish";
            this.btnPublish.Size = new System.Drawing.Size(75, 23);
            this.btnPublish.TabIndex = 49;
            this.btnPublish.Text = "发布";
            this.btnPublish.UseVisualStyleBackColor = true;
            this.btnPublish.Click += new System.EventHandler(this.btnPublish_Click);
            // 
            // btnSubscribe
            // 
            this.btnSubscribe.Location = new System.Drawing.Point(117, 286);
            this.btnSubscribe.Name = "btnSubscribe";
            this.btnSubscribe.Size = new System.Drawing.Size(75, 23);
            this.btnSubscribe.TabIndex = 48;
            this.btnSubscribe.Text = "订阅";
            this.btnSubscribe.UseVisualStyleBackColor = true;
            this.btnSubscribe.Click += new System.EventHandler(this.btnSubscribe_Click);
            // 
            // txtContent
            // 
            this.txtContent.Location = new System.Drawing.Point(92, 377);
            this.txtContent.Name = "txtContent";
            this.txtContent.Size = new System.Drawing.Size(100, 21);
            this.txtContent.TabIndex = 47;
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(45, 380);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(29, 12);
            this.label5.TabIndex = 46;
            this.label5.Text = "内容";
            // 
            // txtTopicPublish
            // 
            this.txtTopicPublish.Location = new System.Drawing.Point(92, 341);
            this.txtTopicPublish.Name = "txtTopicPublish";
            this.txtTopicPublish.Size = new System.Drawing.Size(100, 21);
            this.txtTopicPublish.TabIndex = 45;
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(45, 344);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(29, 12);
            this.label6.TabIndex = 44;
            this.label6.Text = "主题";
            // 
            // txtTopic
            // 
            this.txtTopic.Location = new System.Drawing.Point(92, 248);
            this.txtTopic.Name = "txtTopic";
            this.txtTopic.Size = new System.Drawing.Size(100, 21);
            this.txtTopic.TabIndex = 43;
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(45, 251);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(29, 12);
            this.label7.TabIndex = 42;
            this.label7.Text = "主题";
            // 
            // btnDisconnect
            // 
            this.btnDisconnect.Location = new System.Drawing.Point(130, 205);
            this.btnDisconnect.Name = "btnDisconnect";
            this.btnDisconnect.Size = new System.Drawing.Size(75, 23);
            this.btnDisconnect.TabIndex = 41;
            this.btnDisconnect.Text = "断开";
            this.btnDisconnect.UseVisualStyleBackColor = true;
            this.btnDisconnect.Click += new System.EventHandler(this.btnDisconnect_Click);
            // 
            // btnConnect
            // 
            this.btnConnect.Location = new System.Drawing.Point(36, 205);
            this.btnConnect.Name = "btnConnect";
            this.btnConnect.Size = new System.Drawing.Size(75, 23);
            this.btnConnect.TabIndex = 40;
            this.btnConnect.Text = "连接";
            this.btnConnect.UseVisualStyleBackColor = true;
            this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);
            // 
            // txtClientId
            // 
            this.txtClientId.Location = new System.Drawing.Point(67, 164);
            this.txtClientId.Name = "txtClientId";
            this.txtClientId.Size = new System.Drawing.Size(134, 21);
            this.txtClientId.TabIndex = 39;
            this.txtClientId.Text = "snake";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(20, 167);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(41, 12);
            this.label4.TabIndex = 38;
            this.label4.Text = "客户ID";
            // 
            // txtUpwd
            // 
            this.txtUpwd.Location = new System.Drawing.Point(67, 127);
            this.txtUpwd.Name = "txtUpwd";
            this.txtUpwd.Size = new System.Drawing.Size(134, 21);
            this.txtUpwd.TabIndex = 37;
            this.txtUpwd.Text = "1";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(32, 130);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(29, 12);
            this.label3.TabIndex = 36;
            this.label3.Text = "密码";
            // 
            // txtUserName
            // 
            this.txtUserName.Location = new System.Drawing.Point(67, 100);
            this.txtUserName.Name = "txtUserName";
            this.txtUserName.Size = new System.Drawing.Size(134, 21);
            this.txtUserName.TabIndex = 35;
            this.txtUserName.Text = "a";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(32, 103);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(29, 12);
            this.label2.TabIndex = 34;
            this.label2.Text = "账号";
            // 
            // txtPort
            // 
            this.txtPort.Location = new System.Drawing.Point(67, 64);
            this.txtPort.Name = "txtPort";
            this.txtPort.Size = new System.Drawing.Size(134, 21);
            this.txtPort.TabIndex = 33;
            this.txtPort.Text = "12345";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(32, 67);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(29, 12);
            this.label1.TabIndex = 32;
            this.label1.Text = "端口";
            // 
            // txtIP
            // 
            this.txtIP.Location = new System.Drawing.Point(67, 22);
            this.txtIP.Name = "txtIP";
            this.txtIP.Size = new System.Drawing.Size(134, 21);
            this.txtIP.TabIndex = 31;
            this.txtIP.Text = "127.0.0.1";
            // 
            // lb
            // 
            this.lb.AutoSize = true;
            this.lb.Location = new System.Drawing.Point(20, 25);
            this.lb.Name = "lb";
            this.lb.Size = new System.Drawing.Size(41, 12);
            this.lb.TabIndex = 30;
            this.lb.Text = "IP地址";
            // 
            // FormMqttClient
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(874, 525);
            this.Controls.Add(this.rtxtMessage);
            this.Controls.Add(this.label8);
            this.Controls.Add(this.btnPublish);
            this.Controls.Add(this.btnSubscribe);
            this.Controls.Add(this.txtContent);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.txtTopicPublish);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.txtTopic);
            this.Controls.Add(this.label7);
            this.Controls.Add(this.btnDisconnect);
            this.Controls.Add(this.btnConnect);
            this.Controls.Add(this.txtClientId);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.txtUpwd);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.txtUserName);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.txtPort);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtIP);
            this.Controls.Add(this.lb);
            this.Name = "FormMqttClient";
            this.Text = "FormMqttClient";
            this.Load += new System.EventHandler(this.FormMqttClient_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.RichTextBox rtxtMessage;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.Button btnPublish;
        private System.Windows.Forms.Button btnSubscribe;
        private System.Windows.Forms.TextBox txtContent;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.TextBox txtTopicPublish;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.TextBox txtTopic;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.Button btnDisconnect;
        private System.Windows.Forms.Button btnConnect;
        private System.Windows.Forms.TextBox txtClientId;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.TextBox txtUpwd;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox txtUserName;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox txtPort;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox txtIP;
        private System.Windows.Forms.Label lb;
    }
}

窗体FormMqttClient程序代码如下:客户端程序

文件FormMqttClient.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MQTTnet;
using MQTTnet.Client;

namespace CultureDemo
{
    public partial class FormMqttClient : Form
    {
        IMqttClient mqttClient;
        public FormMqttClient()
        {
            InitializeComponent();
            rtxtMessage.ReadOnly = true;
        }

        /// <summary>
        /// 打印相关消息
        /// </summary>
        /// <param name="contents"></param>
        private void DisplayMessage(string contents)
        {
            if (!this.IsHandleCreated)
            {
                return;
            }
            this.BeginInvoke(new Action(() =>
            {
                if (rtxtMessage.TextLength >= 40960)
                {
                    rtxtMessage.Clear();
                }
                rtxtMessage.AppendText($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}->{contents}\n");
                rtxtMessage.ScrollToCaret();
            }));
        }

        private void FormMqttClient_Load(object sender, EventArgs e)
        {
            mqttClient = new MqttFactory().CreateMqttClient();
            mqttClient.ConnectedAsync += MqttClient_ConnectedAsync;
            mqttClient.DisconnectedAsync += MqttClient_DisconnectedAsync;
            mqttClient.ApplicationMessageReceivedAsync += MqttClient_ApplicationMessageReceivedAsync;
        }

        private Task MqttClient_ApplicationMessageReceivedAsync(MqttApplicationMessageReceivedEventArgs e)
        {
            return Task.Run(new Action(() =>
            {
                string msg = e.ApplicationMessage.ConvertPayloadToString();
                DisplayMessage($"接收消息:{msg}\nQoS={e.ApplicationMessage.QualityOfServiceLevel}\n客户端={e.ClientId}\n主题:{e.ApplicationMessage.Topic}");
            }));
        }

        private Task MqttClient_DisconnectedAsync(MqttClientDisconnectedEventArgs e)
        {
            return Task.Run(new Action(async () =>
            {
                DisplayMessage($"已断开到MQTT服务端的连接.尝试重新连接");
                try
                {
                    await Task.Delay(3000);
                    //MqttClientOptions options = new MqttClientOptions();
                    //await mqttClient.ConnectAsync(options);
                    await mqttClient.ReconnectAsync();
                }
                catch (Exception ex)
                {
                    DisplayMessage($"重新连接服务器失败:{ex.Message}");
                }
            }));
        }

        private Task MqttClient_ConnectedAsync(MqttClientConnectedEventArgs e)
        {
            return Task.Run(new Action(() =>
            {
                DisplayMessage($"连接到MQTT服务端成功.{e.ConnectResult.AssignedClientIdentifier}");
            }));
        }

        private async void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                MqttClientOptionsBuilder mqttClientOptionBuild = new MqttClientOptionsBuilder()
                 .WithClientId(this.txtClientId.Text)
                 .WithTcpServer(this.txtIP.Text, int.Parse(this.txtPort.Text))
                 .WithCredentials(this.txtUserName.Text, this.txtUpwd.Text);
                MqttClientOptions options = mqttClientOptionBuild.Build();
                //开启
                await mqttClient.ConnectAsync(options);
            }
            catch (Exception ex) 
            {
                DisplayMessage($"连接服务端时出现异常:{ex.Message}");
            }
        }

        private async void btnDisconnect_Click(object sender, EventArgs e)
        {
            if (mqttClient != null)
            {
                if (mqttClient.IsConnected)
                {
                    await mqttClient.DisconnectAsync();
                }
                mqttClient.Dispose();
            }
        }

        private async void btnSubscribe_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.txtTopic.Text))
            {
                DisplayMessage(">>> 请输入主题");
                return;
            }
            //在 MQTT 中有三种 QoS 级别: QuanlityOfService
            //At most once(0) 最多一次
            //At least once(1) 至少一次
            //Exactly once(2) 恰好一次
            MqttClientSubscribeOptionsBuilder subscribeOptionsBuilder = new MqttClientSubscribeOptionsBuilder();
            MqttClientSubscribeOptions subscribeOption = subscribeOptionsBuilder.WithTopicFilter(this.txtTopic.Text).Build();
            await mqttClient.SubscribeAsync(subscribeOption);
            DisplayMessage($">>> 成功订阅主题【{txtTopic.Text}】");
        }

        private async void btnPublish_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.txtTopicPublish.Text))
            {
                DisplayMessage(">>> 请输入主题");
                return;
            }
            MqttClientPublishResult result = await mqttClient.PublishStringAsync(
                this.txtTopicPublish.Text,
                this.txtContent.Text,
                MQTTnet.Protocol.MqttQualityOfServiceLevel.AtLeastOnce);//恰好一次, QoS 级别1   
            DisplayMessage($"发布消息--主题:{this.txtTopicPublish.Text},消息:{this.txtContent.Text},结果: {result.ReasonCode}");
        }
    }
}

为了一个应用程序可以作为客户端和服务端,我们在Program.cs增加切换开关

选择作为MQTT服务端和MQTT客户端

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CultureDemo
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            DialogResult dialog = MessageBox.Show("请选择程序作为MQTT服务端还是客户端,选择\"是\"作为服务端,选择\"否\"作为客户端", "是否MQTT服务端", MessageBoxButtons.YesNo);
            if (dialog == DialogResult.Yes)
            {
                Application.Run(new FormMqttServer());
            }
            else 
            {
                Application.Run(new FormMqttClient());
            }
        }
    }
}

程序运行如图:

运行客户端与服务端通信

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2106873.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【软件测试】软件测试-----什么是Bug?Bug是如何分级的?Bug的生命周期是怎样的?如何描述一个Bug?

博客目录 一.软件测试的生命周期二.BUG的定义和级别2.1 bug的概念.2.2 如何描述一个bug.2.3bug的级别2.3.1 bug分级的意义.2.3.2 bug的四种级别. 三.BUG的生命周期.四.当与开发人员发生冲突该如何处理(高频面试)五.总结 一.软件测试的生命周期 软件测试贯穿于软件的整个生命周…

Day-02-QPushButton设置信号与槽一在UI界面直接设置槽函数

1.点击UI界面 2.选择Push Button按键 3.右键选择转到槽 4.根据自己的需要选择信号事件 5.在自动生成的函数内编写自己需要完成的动作

【网络安全】服务基础第一阶段——第十一节:Windows系统管理基础----PKI技术与应用

目录​​​​​​​ 一、加密技术 1.1 基本保密通信模型 1.2 密码学发展 1.2.1 古典密码学&#xff08;1949年前&#xff09; 1.2.2 近代密码学&#xff08;1949&#xff5e;1975年&#xff09; 1.2.3 现代密码学&#xff08;1976年以后&#xff09; 1.3 古典密码 1.3.…

基因组学中的深度学习

----/ START /---- 基因组学其实是一门将数据驱动作为主要研究手段的学科&#xff0c;机器学习方法和统计学方法在基因组学中的应用一直都比较广泛。 不过现在多组学数据进一步激增——这个从目前逐渐增多的各类大规模人群基因组项目上可以看出来&#xff0c;这其实带来了新的挑…

数字签名,数字证书,时间戳

简介 数字签名、数字证书和时间戳是现代网络安全技术中的重要组成部分&#xff0c;它们共同确保了数据传输的安全性和完整性。 数字签名 数字签名是一种基于公钥加密技术的电子签名方式。它通过使用发送方的私钥对消息进行加密生成一个特定的签名值&#xff0c;并将该签名值与…

四川财谷通抖音小店新宠儿,科技生活一键购!

在数字经济蓬勃发展的今天&#xff0c;电商平台如雨后春笋般涌现&#xff0c;其中抖音小店凭借其庞大的用户基础、精准的算法推荐以及创新的营销模式&#xff0c;成为了众多商家竞相入驻的热门选择。而四川财谷通信息技术有限公司&#xff0c;作为这一领域内的佼佼者&#xff0…

煤矿广播通信系统

在煤矿这样的特殊工作环境中&#xff0c;煤矿广播通信系统发挥着至关重要的作用。它就如同煤矿中的“传音使者”&#xff0c;保障着各项工作的顺利进行和人员的安全。 系统功能 煤矿广播通信系统具备多种强大的功能。首先&#xff0c;它拥有实时广播功能&#xff0c;能够及时传…

应用商店优化(ASO)的四大误区

应用商店优化 (ASO) 是移动营销中最重要的部分之一&#xff0c;可以帮助开发人员吸引自然流量并在应用推广方面取得预期效果。近年来ASO优化在开发者中越来越受欢迎。虽然它已经证明了其有效性和对应用成功的影响力&#xff0c;但尽管如此仍然存在与ASO相关的误解&#xff0c;导…

Rust 赋能前端:PDF 分页/关键词标注/转图片/抽取文本/抽取图片/翻转...

❝ 我从不幻想成功。我只会为了成功努力实践 大家好&#xff0c;我是柒八九。一个专注于前端开发技术/Rust及AI应用知识分享的Coder ❝ 此篇文章所涉及到的技术有 WebAssembly Mupdf Pdf操作( 分页展示/文本抽离/文本标注/获取超链接/Pdf转图片/翻转/截取) 因为&#xff0c;行文…

Chrome 浏览器插件获取网页 window 对象(方案一)

前言 最近有个需求&#xff0c;是在浏览器插件中获取 window 对象下的某个数据&#xff0c;当时觉得很简单&#xff0c;和 document 一样&#xff0c;直接通过嵌入 content_scripts 直接获取&#xff0c;然后使用 sendMessage 发送数据到插件就行了&#xff0c;结果发现不是这…

【unplugin-vue-router】超级实用的自动路由,具体使用教程!

一、安装 vite 创建vue项目的时候选择 auto import 【推荐】 二、使用 原理&#xff1a;参考 vite 官网 来看一个简单的例子&#xff1a; 这是项目的pages目录结构 src/pages/ ├── index.vue ├── about.vue └── users/├── index.vue└── [id].vueunplugin-…

C语言08--指针数组结合

前言&#xff1a; 这次的指针数组结合乃作者呕心沥血之作&#xff0c;大家翻翻进度条就知道了&#xff0c;内容十分干货&#xff0c;各位读者若能全部耐心解析读懂了&#xff0c;想必也能理解掌握C语言中的数组指针这两把利剑了。 指针数组结合&#xff1a; 指针数组 概念&a…

异步编程学习

UniTask UniTask 访问UniTask的GitHub的主页可以直接下载unity Package进行导入&#xff0c;或者通过 Package Manager导入&#xff0c;导入完成之后根据文档加一下 宏定义“UNITASK_DOTWEEN_SUPPORT” 这样就可以正常的控制DoTween了 2.UniTask 的简单使用 // UniTask 是可以作…

lambda表达式用法——C#学习笔记

“Lambda 表达式”是一个匿名函数&#xff0c;它可以包含表达式和语句&#xff0c;并且可用于创建委托或表达式目录树类型。 实例如下&#xff1a; 代码如下&#xff1a; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.…

景联文科技:专业视频标注服务助力计算机视觉应用升级

视频标注是指对视频内容进行分析&#xff0c;并在视频中的特定对象、行为或事件上添加标签的过程。 视频标注包括&#xff1a; 1. 对象检测与跟踪 •对象检测&#xff1a;在每一帧中识别并定位特定的对象&#xff0c;如人、车、动物等。 •对象跟踪&#xff1a;跟踪这些对象…

你知道吗?Python现在这么火爆的真相!

Python之所以如此火爆&#xff0c;主要得益于其多方面的优势和广泛的应用场景。以下是对Python火爆原因的详细归纳&#xff1a; 1. 易学易用 语法简洁&#xff1a;Python的语法设计非常简洁、直观&#xff0c;易于学习和理解。初学者能够快速上手&#xff0c;减少编写代码时的…

解决linux云服务器ping不通另一台linux云服务器的问题

这里以华为云服务器为例 1、找到云主机详情&#xff1a;xxx实例 / 实例概览 / 服务器详情&#xff0c;找到安全组 2、找到云主机当前在使用的安全组&#xff0c;添加入向规则 注意这里要选择 ICMP 协议&#xff0c;因为 ping 的协议是基于 ICMP 协议工作的 3、再次ping即可通 …

多目标应用:四种多目标优化算法(NSGA2、NSPSO、NSDBO、NSCOA)求解柔性作业车间调度问题(FJSP),MATLAB代码

一、柔性作业车间调度问题 柔性作业车间调度问题(Flexible Job Scheduling Problem, FJSP) 的描述如下&#xff1a;n个工件 { J , J 2 , . . , J n } \{J,J_2,..,J_n\} {J,J2​,..,Jn​}要在 m m m 台机器 { M 1 , M 2 , . . , M m } \{M_1,M_2,..,M_m\} {M1​,M2​,..,Mm​} …

linux基础IO——动静态库——实现与应用学习、原理深度解析

前言&#xff1a;本节内容是基础IO部分的动静态库。 本节内容&#xff0c; 我们将站在实现者的角度上自己实现一下动静态库&#xff0c; 并且会站在使用者的角度上使用我们自己实现的库。过程中牵扯到许多新的知识&#xff0c; 最后我们会重谈一下我们的进程。 理解一下有了动静…

【Python基础】想学好Python,就必须要知道的Python知识。一篇文章带你了解Python,学好Python!!!

Python知识涵盖面非常广泛&#xff0c;从基础语法到高级特性&#xff0c;再到丰富的库和框架&#xff0c;都是Python学习的重要组成部分。 一、基础语法 变量与数据类型&#xff1a; Python是动态类型语言&#xff0c;变量无需声明类型&#xff0c;直接赋值即可。常见的数据类…