MVC应用程序中的MQTT客户端 [英] MQTT client in MVC application

查看:466
本文介绍了MVC应用程序中的MQTT客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究充当MQTT客户端的MVC应用程序.我正在使用来自paho的C#库M2Mqtt.基本上,每次有人按下我的网站上的按钮时,我都希望发布一条消息,并且它也会收到一个答案(因此它也订阅一个主题.)

I'm working on a MVC application that serves as a MQTT client. I'm using the C# library M2Mqtt from paho. Basicly every time someone presses a button on my website, I want a message to be published, and it will recieve an answer aswell (thus it subscribes to a topic aswell.)

我的问题是:按下按钮(调用发布消息的ActionResult)时是否必须再次连接到代理,或者是否有办法保持连接有效(例如在Global中初始化它)?那怎么办呢? 由于我对MVC/.net编程还很陌生,所以我对所有的来龙去脉都不熟悉,因此我很难自己解决这个问题. 对此事的任何帮助,我们将不胜感激! :-)

My question is: do I have to connect to the broker every time again when pressing the button (calling an ActionResult that publishes the message) or is there a way to keep the connection alive (f.e. initializing it in Global?) and how would one do that then? As I'm fairly new to MVC/.net programming I'm not familiar with all ins and outs, and am kind of struggling to figure this out on my own. Any help on the matter is much appreciated! :-)

推荐答案

我是M2Mqtt开发人员:-) 当您在M2Mqtt客户端中使用Connect方法时,由于具有ping消息的保持活动机制,连接仍然保持活动状态.如果您没有在指定的超时时间内发送消息,则客户端将使用与代理之间的ping消息来使它保持活动状态.

I'm the M2Mqtt developer :-) When you use Connect method in the M2Mqtt client, the connection is still alive thanks to a keep alive mechanism with ping messages. If you don't send message for the specified timeout, the client mantains it alive using ping messages with the broker.

发送每条消息都不需要连接.可以一次连接.

You don't need to connect for every message to send .. you can connect one time.

保罗

这篇关于MVC应用程序中的MQTT客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆