[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
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
to messages.
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(...) anywhere in
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
processing subscriptions.
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
and
rpc_math_srvr.cpp). Both of those use a single
connection for publishing and subscribing.
Frank
On 10/14/20 5:13 AM, jayesh kulkarni
wrote:
Hi All,
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
subscription).
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
paho-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/paho-dev