资源简介
c#实现消息推送,具体的配置和用法,请点击本人的博客,http://www.cnblogs.com/xlxr45/p/7623587.html
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using uPLibrary.Networking.M2Mqtt;
using uPLibrary.Networking.M2Mqtt.Messages;
namespace MqttCsharp
{
public partial class Form1 : Form
{
private MqttClient client;
private string topic = ““;
private delegate void MessDelegate(T obj);
public Form1()
{
InitializeComponent();
buttonLose.Enabled = false;
buttonca.Enabled = false;
}
//连接apache apollo
private void linkClick(object sender EventArgs e)
{
string clientId = ““;
string ip = ““;
string port = ““;
if (String.IsNullOrEmpty(textBoxCT.Text))
{
MessageBox.Show(“请输入客户机标识!“);
return;
}
if (String.IsNullOrEmpty(textBoxAD.Text) && textBoxAD.Text.IndexOf(‘:‘)<=0)
{
MessageBox.Show(“请输入IP地址且带端口号!“);
return;
}
clientId = textBoxCT.Text;
ip = textBoxAD.Text.Substring(0textBoxAD.Text.IndexOf(‘:‘));
port = textBoxAD.Text.Substring(textBoxAD.Text.IndexOf(‘:‘)+1);
try
{
client = new MqttClient(IPAddress.Parse(ip) Convert.ToInt32(port) false null);
client.Connect(clientId “admin“ “password“ false 0x01 false null null true 60);//admin和password是之前在apache apollo中设置的用户名和密码
buttonlink.Enabled = false;
buttonLose.Enabled = true;
textBoxLS.ForeColor = Color.RoyalBlue;
textBoxLS.Text = “已连接“;
}
catch (Exception ee)
{
MessageBox.Show(“无法连接,请确定代理服务器是否启动,IP端口是否正确“);
}
}
//断开apache apollo连接
private void Closelink(object sender EventArgs e)
{
if (client !=null && client.IsConnected)
{
client.Disconnect();
client = null;
buttonlink.Enabled = true;
buttonLose.Enabled = false;
textBoxLS.ForeColor = Color.Firebrick;
textBoxLS.Text = “断开连接“;
}
}
//发布按钮的点击时间
private void PublishSubmit(object sender EventArgs e)
{
string pubtitle = ““;//发布主题
byte pubQu ;//发布质量
if (String.IsNullOrEmpty(textBoxPuIt.Text))
{
MessageBox.Show(“请输入发布主题!“);
return;
}
if (String.IsNullOrEmpty(comboBoxPub.Text))
{
MessageBox.Show(“请选择发布主题质量!“);
ret
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 187 2017-10-03 15:13 MqttCsharp\MqttCsharp\App.config
文件 40448 2017-10-03 16:06 MqttCsharp\MqttCsharp\bin\Debug\M2Mqtt.dll
文件 17408 2017-10-03 17:52 MqttCsharp\MqttCsharp\bin\Debug\MqttCsharp.exe
文件 187 2017-10-03 15:13 MqttCsharp\MqttCsharp\bin\Debug\MqttCsharp.exe.config
文件 30208 2017-10-03 17:52 MqttCsharp\MqttCsharp\bin\Debug\MqttCsharp.pdb
文件 22984 2017-10-03 17:53 MqttCsharp\MqttCsharp\bin\Debug\MqttCsharp.vshost.exe
文件 187 2017-10-03 15:13 MqttCsharp\MqttCsharp\bin\Debug\MqttCsharp.vshost.exe.config
文件 490 2017-03-19 05:00 MqttCsharp\MqttCsharp\bin\Debug\MqttCsharp.vshost.exe.manifest
文件 7186 2017-10-03 17:59 MqttCsharp\MqttCsharp\Form1.cs
文件 18595 2017-10-03 17:48 MqttCsharp\MqttCsharp\Form1.Designer.cs
文件 5817 2017-10-03 17:48 MqttCsharp\MqttCsharp\Form1.resx
文件 3917 2017-10-03 16:10 MqttCsharp\MqttCsharp\MqttCsharp.csproj
文件 863 2017-10-03 15:14 MqttCsharp\MqttCsharp\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 7026 2017-10-03 16:08 MqttCsharp\MqttCsharp\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 811 2017-10-03 17:53 MqttCsharp\MqttCsharp\obj\Debug\MqttCsharp.csproj.FileListAbsolute.txt
文件 975 2017-10-03 17:48 MqttCsharp\MqttCsharp\obj\Debug\MqttCsharp.csproj.GenerateResource.Cache
文件 6687 2017-10-03 16:10 MqttCsharp\MqttCsharp\obj\Debug\MqttCsharp.csprojResolveAssemblyReference.cache
文件 17408 2017-10-03 17:52 MqttCsharp\MqttCsharp\obj\Debug\MqttCsharp.exe
文件 180 2017-10-03 17:48 MqttCsharp\MqttCsharp\obj\Debug\MqttCsharp.Form1.resources
文件 30208 2017-10-03 17:52 MqttCsharp\MqttCsharp\obj\Debug\MqttCsharp.pdb
文件 180 2017-10-03 16:10 MqttCsharp\MqttCsharp\obj\Debug\MqttCsharp.Properties.Resources.resources
文件 0 2017-10-03 15:14 MqttCsharp\MqttCsharp\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2017-10-03 15:14 MqttCsharp\MqttCsharp\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2017-10-03 15:14 MqttCsharp\MqttCsharp\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
文件 522 2017-10-03 15:13 MqttCsharp\MqttCsharp\Program.cs
文件 1340 2017-10-03 15:13 MqttCsharp\MqttCsharp\Properties\AssemblyInfo.cs
文件 2872 2017-10-03 15:13 MqttCsharp\MqttCsharp\Properties\Resources.Designer.cs
文件 5612 2017-10-03 15:13 MqttCsharp\MqttCsharp\Properties\Resources.resx
文件 1097 2017-10-03 15:13 MqttCsharp\MqttCsharp\Properties\Settings.Designer.cs
文件 249 2017-10-03 15:13 MqttCsharp\MqttCsharp\Properties\Settings.settings
............此处省略13个文件信息
评论
共有 条评论