Hi Rene, That all sounds quite straightforward. You might want to check out the still very much a work in progress "client-thread" branch in the repo: https://bitbucket.org/oojah/mosquitto/changesets/tip/branch(%22client-thread%22) It adds support for running mosquitto_loop() in its own thread and perhaps more importantly adds synchronisation everywhere it is needed.
Cheers, Roger On Mon, Mar 5, 2012 at 10:52 PM, Rene Lösch <[email protected]> wrote: > Hi Roger, > > Thanks for your example, it gave me helpful clues to improve my code > elsewhere. > > I totally agree with you, it depends on the requirements. Maybe it is better > to state my requirements more precisely: > In your example your client's publish depends on the "on_message event". In > my client publish and subscribe should be independent of each other but they > should share the same loop-method (in other words, the same connection to > the broker). The client should listen on its socket for inbound messages but > the listener should not halt the whole program. If a message arrives, my > on_message-callback-function transfers this message to an external > message-handler object, which interprets the content and does further > processing, but this is not relevant for the client. And finally, an > external event (function call) should always be able to trigger a publish. > > A pattern would be the IA91 Java client provided by IBM. The client connects > to the broker, topics can be subscribed and while the client is publishing > messages other messages from the broker can be received. > > So, my client should only be responsible for receiving and sending messages > but it should be able to do both at the same time. External modules can > trigger a publish by calling the client's publish-method (together with a > reference to a message-object) and inbound messages get transferred to > another module, let's call it MessageHandler. And for the final step of the > project it is necessary to run the whole client in at least one thread > independent from the main process. Because my client is only a smaller part > of a project und should not affect the other modules. Therefore an exclusive > usage of the main() isn't possible. > > I know this is not a very technical description, but rather a first approach > to summarize the functionallity in writing. Please tell me, if something > needs further explanation (perhaps with UML). > > Rene _______________________________________________ Mailing list: https://launchpad.net/~mqtt-users Post to : [email protected] Unsubscribe : https://launchpad.net/~mqtt-users More help : https://help.launchpad.net/ListHelp

