# ZeroMQ on Legato?

**URL:** <https://forum.legato.io/t/zeromq-on-legato/88>\
**Category:** Legato Application Framework\
**Created:** [December 3, 2014, 8:17am UTC](https://forum.legato.io/t/zeromq-on-legato/88 "2014-12-03T08:17:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![s1nndev](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@s1nndev](https://forum.legato.io/u/s1nndev)\
**Post date:** [December 3, 2014, 8:17am UTC](https://forum.legato.io/t/zeromq-on-legato/88/1 "2014-12-03T08:17:58Z")

</div>

Hello everyone,

I have a problem that I can’t solve without any help:  
After I tried some test programs with the WP7102 I wanted to use ZeroMQ as a message broker for my future programs.  
So I installed the library on my host and on my target and the “hello world” sample from ZeroMQ works on the target as well as on the host, so I think I installed the libraries correctly.  
Now I wanted to write this “hello world” sample from ZeroMQ in Legato and the only thing I changed is I used LE\_INFO instead of printf and COMPONENT\_INIT instead of int main (void).  
But there always appears the same error:

root@swi-mdm9x15:~# app start zmq  
Starting app ‘zmq’…  
DONE  
myServer: error while loading shared libraries: libzmq.so.4: cannot open shared object file: No such file or directory  
myClient: error while loading shared libraries: libzmq.so.4: cannot open shared object file: No such file or directory  
root@swi-mdm9x15:~# app status  
[running] airvantage  
[running] audioService  
[running] cellNetService  
[running] dataConnectionService  
[running] modemService  
[running] positioningService  
[running] voiceCallService  
[stopped] zmq

Here is the logread from the “app start zmq” command: [attachment=2]recording app start logread.txt[/attachment]

In the .adef file I included the library in the “bundles” section like the following:  
bundles:  
{  
file:  
{  
[r] libzmq.so.4.0.0 /lib  
}  
}

And in the .cdef files like the following:  
requires:  
{  
lib:  
{  
zmq  
}  
}

When I try to execute only the client or only the server in the .adef file, it doesn’t work, too.  
Also here is what comes when I type the “make wp7” command and what I get when I run the “instapp” command: [attachment=0]recording make wp7.txt[/attachment]  
[attachment=1]recording instapp.txt[/attachment]

I hope you can help me 🙂

Thank you!  
Daniel

---

<div class="post-metadata">

**Author:** ![s1nndev](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@s1nndev](https://forum.legato.io/u/s1nndev)\
**Post date:** [December 3, 2014, 8:20am UTC](https://forum.legato.io/t/zeromq-on-legato/88/2 "2014-12-03T08:20:33Z")

</div>

And here is my app:  
[attachment=0]zmqTest.zip[/attachment]

---

<div class="post-metadata">

**Author:** ![jchitty](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jchitty/32/72_2.png) [@jchitty](https://forum.legato.io/u/jchitty)\
**Post date:** [December 3, 2014, 11:53pm UTC](https://forum.legato.io/t/zeromq-on-legato/88/3 "2014-12-03T23:53:50Z")

</div>

Hi, Daniel,

It looks like your program is trying to open libzmq.so.4, but the library appears in your application’s sandbox as libzmq.so.4.0.0.

If you change the bundles section to this, it should work:

```auto
bundles:
{
  file:
  {
    [r] libzmq.so.4.0.0 /lib/libzmq.so.4
  }
}
```

---

<div class="post-metadata">

**Author:** ![jchitty](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/jchitty/32/72_2.png) [@jchitty](https://forum.legato.io/u/jchitty)\
**Post date:** [December 4, 2014, 12:49am UTC](https://forum.legato.io/t/zeromq-on-legato/88/4 "2014-12-04T00:49:23Z")

</div>

Note that because your COMPONENT\_INIT functions never return, your program will never be able to process any other events. In your trivial sample app, this is not a problem, but if you want to start using asynchronous notification features of some APIs (such as the le\_data API’s notification when your cellular data connection comes up or goes down), you’ll need to either spawn another thread or find a way to return from your COMPONENT\_INIT.

Obviously, if you go multi-threaded, then you have to worry about races between threads, etc.

Fortunately, 0MQ provides a mechanism for integrating with other event loops, and that works with ours too.

The function zmq\_getsockopt() can be used to fetch the file descriptor associated with the 0MQ socket (option ZMQ\_FD). This can then be monitored for “readability” using a Legato “file descriptor monitor” ([legato.io/legato-docs/14\_10/ … vent\_files](http://www.legato.io/legato-docs/14_10/c_event_loop.html#c_event_files)).

After you have created a file descriptor monitor and set your “readability” handler function, when a message arrives on your 0MQ socket, your handler function will be called. You should move your while loop into that handler function. But, remember to make sure that loop doesn’t block, or you’ll just be stopping your event loop there instead of in your COMPONENT\_INIT. You can do a non-blocking zmq\_recv() (using the ZMQ\_DONTWAIT option flag) and return from your handler function if zmq\_recv() reports that there’s nothing to receive.

I hope this helps!

–Jen

---

<div class="post-metadata">

**Author:** ![s1nndev](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@s1nndev](https://forum.legato.io/u/s1nndev)\
**Post date:** [December 4, 2014, 3:48pm UTC](https://forum.legato.io/t/zeromq-on-legato/88/5 "2014-12-04T15:48:52Z")

</div>

Thanks a lot for your help!
