Comments (10)
Hi,
your code likes fine so far. For your case you need one server and several clients. So you need a parameter to distinguish the clients in your client code (i.e. parameter).
It is not possible to send a message directly to a special client. You can only publish a message to the server. Depending on the topic several clients can subscribe to that topic. You can build your own patterns based on it. So if you need to send a message to client1 you can send them to something like client/1/messages and client1 is the only one who has subscribed that topic. For example with client/1/+.
Please find more information here: http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices
If you have more questions please let me know.
Best regards
Christian
from mqttnet.
Hi @chkr1011,
thanks for your fast response and the link.
I tried out the following:
Client_2:
var applicationMessage = new MqttApplicationMessage(
"client/1/messages",
Encoding.UTF8.GetBytes("Hello World"),
MqttQualityOfServiceLevel.ExactlyOnce,
false
);
Console.WriteLine("Sending");
client.PublishAsync(applicationMessage);
And Client_1:
client.Connected += async (s,e) =>
{
Console.WriteLine("### CONNECTED WITH SERVER ###");
await client.SubscribeAsync(new List
{
new TopicFilter("client/1/+", MqttQualityOfServiceLevel.AtLeastOnce)
});
And it worked like a charm. Thank you so much!
But to my second question: Can the server log somehow the incomming messages?
Best regards,
Zuendelmeister
from mqttnet.
You can use the MqttTrace class to attach a handler for general trace and debug messages. But there you will not see the content of the messages etc.
Or do you need something different?
from mqttnet.
I was hoping to log all incomming and outgoing messages in the broker program. But if thats not possible I have to live without it. Thanks.
from mqttnet.
I can add it if you like. It should be not a huge change. You need the ApplicationMessages and the sending ClientId only? I assume you don't need the low level packages or?
from mqttnet.
Gread that would be awsome.
What I need is the ApplicationMessage, the ClientId, the MqttQualityOfServiceLevel and the topic. The retain information could come in handy too but this is not important.
Thank you =)
from mqttnet.
OK this what you need is all part of the ApplicationMessage excluding the ClientId. I will add a event which gives you both. Give me a few days to implement it.
from mqttnet.
Perfect =)
from mqttnet.
Hi, I added this feature to master. Please test it and tell me if it fits your needs. It is a new event at the MqttServer available.
from mqttnet.
I released a new version. If you need something please let me know (open the ticket).
from mqttnet.
Related Issues (20)
- My client receive Disconnected when I set mqqtv5 to connect emqx bloker HOT 1
- Mqtt client with web API
- Client and server channels based on WebsocketSharp implementation of web sockets
- The server shuts down too slowly. HOT 2
- Support for RecyclableMemoryManager, client write support for ReadOnlySequence as payload
- MqttClient.ConnectAsync() with Tls enabled: 'RemoteCertificateChainErrors' (RevocationStatusUnknown) on Android, but not on iOS HOT 1
- MQTTnet.Exceptions.MqttCommunicationTimedOutException HResult=0x80131500 Message=The operation has timed out. Source=mscorlib StackTrace: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in System.Runtime.CompilerServices\TaskAwaiter.cs:line 78 此异常最初是在此调用堆栈中引发的: HOT 1
- Issue with Establishing Secure WebSocket Connection to AWS IoT MQTT Server on .NET Framework 4.x
- Requesting the last data from mqtt broker HOT 1
- mqttnet is missing NuGet package README file
- mqttnet.extensions.managedclient is missing NuGet package README file HOT 1
- Get the ClientID of Sender client HOT 1
- How do i authorize whit Username and Password? HOT 1
- Trying to run this sample code(https://github.com/dotnet/MQTTnet) from visual studio 2022 but getting many errors HOT 1
- Not able to run the sample code HOT 2
- Not able to establish tls connection with azure event grid mqtt server HOT 2
- 链接频繁断开【异常断线触发重连】错误信息:Not allowed to connect while connect/disconnect is pending.
- How do you specify the protocol version which MqttServer supports? HOT 1
- Missing assemblies when building the solution HOT 1
- Gg HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqttnet.