Re: [paho-dev] Query related to publisher and subscriber using same client
You don't mention which library you're looking at (C, C++, Python,
Java, Go, etc), but it looks like you mean the C++ one from mqtt::async_client.
But for any of them, including the C++ library, you can
certainly use the same client instance to both publish and subscribe
There aren't any simple examples of a client doing both publish and
subscribe, but it's as easy as starting with a subscriber example
and adding a call to cli.publish(...)
the code while you have a connection. The client is also
thread-safe, so you can use a single client from multiple threads,
such as one thread for publishing messages and another for
There is also a slightly more in-depth example of a Remote Procedure
Call (RPC) client and server for MQTT v5 (rpc_math_cli.cpp
Both of those use a single
connection for publishing and subscribing.
On 10/14/20 5:13 AM, jayesh kulkarni
A question - so far, i have
seen sample examples wherein publisher and subscriber are
separate classes having its own MQTT client (e.g. 1
mqtt::async_client _client for publishing and 1 for
Can we have publisher and
subscriber both implemented in same class using single MQTT
client (mqtt::async_client m_Client)?
Is there any sample example
wherein this is done which i can refer ?
I am trying to do this by
clubbing publisher and subscriber samples. I want to be sure
about the way this is being done. Hence the request.
Thanks in advance.
Kind Regards, Jayesh
paho-dev mailing list
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/paho-dev