← Back to team overview

mosquitto-users team mailing list archive

Re: example subscriber in C

 

Thanks all, I was able to use the code in client_sub.c to get my program
receiving messages.  I can now move past that hurdle.

Tim Champion
tim@xxxxxxxxxxxxxxxxxxx


On Thu, Dec 5, 2013 at 10:29 AM, Roger Light <roger@xxxxxxxxxx> wrote:

> Hi Tim,
>
> Just use "make" in the client directory, remove the line from the
> code, or else add this to your gcc command:
>
> -DVERSION=\"\"
>
> Cheers,
>
> Roger
>
> On Thu, Dec 5, 2013 at 4:25 PM, Tim Champion <tim@xxxxxxxxxxxxxxxxxxx>
> wrote:
> > Not sure why, but when I compile it.
> >
> > I get an error, It compiled fine after I just took out the %s & VERSION,
> but
> > its odd that it doesn't compile cleanly for me.
> >
> > $gcc sub_client.c -lmosquitto -o sub_client
> >
> > sub_client.c: In function ‘print_usage’:
> >
> > sub_client.c:131:75: error: ‘VERSION’ undeclared (first use in this
> > function)
> >
> >   printf("mosquitto_sub version %s running on libmosquitto
> %d.%d.%d.\n\n",
> > VERSION, major, minor, revision);
> >
> >
>    ^
> >
> > sub_client.c:131:75: note: each undeclared identifier is reported only
> once
> > for each function it appears in
> >
> >
> > Tim Champion
> > tim@xxxxxxxxxxxxxxxxxxx
> >
> >
> > On Thu, Dec 5, 2013 at 10:14 AM, Remi SALEMBIER <remi.salembier@xxxxxxx>
> > wrote:
> >>
> >> Hi Tim,
> >>
> >>
> >>
> >> As Sven mentioned, the mosquitto_publish and mosquitto_subscribe clients
> >> sources are provided in the client folder of the sources.
> >>
> >> So you can just extract what you want from the sub_client.c file to
> match
> >> your need.
> >>
> >>
> >>
> >> Remi
> >>
> >>
> >>
> >> De : Mosquitto-users
> >> [mailto:mosquitto-users-bounces+remi.salembier=
> niji.fr@xxxxxxxxxxxxxxxxxxx]
> >> De la part de Sven Klaassen Bos
> >> Envoyé : jeudi 5 décembre 2013 17:10
> >> À : Tim Champion
> >> Cc : mosquitto-users@xxxxxxxxxxxxxxxxxxx
> >> Objet : Re: [Mosquitto-users] example subscriber in C
> >>
> >>
> >>
> >> Hi,
> >>
> >>
> >>
> >> When you download the source code on the mosquitto site, there is a
> >> working publisher and subscriber in the client subfolder. Both written
> in C.
> >>
> >>
> >>
> >> Hope that helps!
> >>
> >>
> >>
> >> Greetings,
> >>
> >> Sven
> >>
> >>
> >>
> >> 2013/12/5 Tim Champion <tim@xxxxxxxxxxxxxxxxxxx>
> >>
> >> Hi, I'm looking for a working example subscriber in C. I have working
> code
> >> that can publish in C, and I can subscribe on the command line, and that
> >> works.
> >>
> >>
> >>
> >> What I can't find is an example C program that does something simple
> like
> >> receive messages and spit them back out to the screen.  My program will
> add
> >> the message payload to a work queue, but that's not the problem I'm
> having.
> >>
> >>
> >>
> >> I tried the code at the bottom of this page:
> >> http://mosquitto.org/man/libmosquitto-3.html but it doesn't seem to
> work.
> >>
> >>
> >>
> >> mosquitto_lib_version returns 1.2.2 if that helps.
> >>
> >>
> >>
> >> Tim Champion
> >>
> >> tim@xxxxxxxxxxxxxxxxxxx
> >>
> >>
> >> --
> >> Mailing list: https://launchpad.net/~mosquitto-users
> >> Post to     : mosquitto-users@xxxxxxxxxxxxxxxxxxx
> >> Unsubscribe : https://launchpad.net/~mosquitto-users
> >> More help   : https://help.launchpad.net/ListHelp
> >>
> >>
> >
> >
> >
> > --
> > Mailing list: https://launchpad.net/~mosquitto-users
> > Post to     : mosquitto-users@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~mosquitto-users
> > More help   : https://help.launchpad.net/ListHelp
> >
>

References