[zeromq-dev] Unable to use ZeroMQ 3.2 in my Android application

Ranjeet Kumar xs2ranjeet at gmail.com
Thu May 16 07:48:13 CEST 2013


Dear Sir,

I did compile the JeroMQ with Android. I changed the localhost to my
server's IP address.
I also make changes in AndroidManifest.xml and allowed the internet access
permission.
android:theme="@style/AppTheme"
android:permission="android.permission.INTERNET">
But still I am getting the exception and app is crashing.

PFB the details.
zmq.Signaler.java
 public void send ()
 {
 ...
  nbytes = w.write(dummy); -> throws android.os.NetworkOnMainThreadException
  ....
 }


05-16 05:37:15.874: I/System.out(883):
android.os.NetworkOnMainThreadException
05-16 05:37:36.003: W/System.err(883):
android.os.NetworkOnMainThreadException
05-16 05:37:36.023: W/System.err(883):     at
android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
05-16 05:37:36.023: W/System.err(883):     at
libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:168)
05-16 05:37:36.033: W/System.err(883):     at
libcore.io.IoBridge.sendto(IoBridge.java:487)
05-16 05:37:36.043: W/System.err(883):     at
java.nio.SocketChannelImpl.writeImpl(SocketChannelImpl.java:378)
05-16 05:37:36.043: W/System.err(883):     at
java.nio.SocketChannelImpl.write(SocketChannelImpl.java:336)
05-16 05:37:36.053: W/System.err(883):     at
java.nio.PipeImpl$PipeSinkChannel.write(PipeImpl.java:114)
05-16 05:37:36.063: W/System.err(883):     at
zmq.Signaler.send(Signaler.java:106)
05-16 05:37:36.063: W/System.err(883):     at
zmq.Mailbox.send(Mailbox.java:90)
05-16 05:37:36.073: W/System.err(883):     at
zmq.Ctx.send_command(Ctx.java:351)
05-16 05:37:36.073: W/System.err(883):     at
zmq.ZObject.send_command(ZObject.java:364)
05-16 05:37:36.083: W/System.err(883):     at
zmq.ZObject.send_plug(ZObject.java:172)
05-16 05:37:36.093: W/System.err(883):     at
zmq.ZObject.send_plug(ZObject.java:163)
05-16 05:37:36.093: W/System.err(883):     at
zmq.Own.launch_child(Own.java:125)
05-16 05:37:36.103: W/System.err(883):     at
zmq.SocketBase.add_endpoint(SocketBase.java:535)
05-16 05:37:36.113: W/System.err(883):     at
zmq.SocketBase.connect(SocketBase.java:526)
05-16 05:37:36.124: W/System.err(883):     at
org.jeromq.ZMQ$Socket.connect(ZMQ.java:917)
05-16 05:37:36.124: W/System.err(883):     at
com.example.jmqtest.MainActivity.onCreate(MainActivity.java:25)
05-16 05:37:36.133: W/System.err(883):     at
android.app.Activity.performCreate(Activity.java:5104)
05-16 05:37:36.133: W/System.err(883):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-16 05:37:36.146: W/System.err(883):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-16 05:37:36.153: W/System.err(883):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-16 05:37:36.163: W/System.err(883):     at
android.app.ActivityThread.access$600(ActivityThread.java:141)
05-16 05:37:36.163: W/System.err(883):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-16 05:37:36.173: W/System.err(883):     at
android.os.Handler.dispatchMessage(Handler.java:99)
05-16 05:37:36.173: W/System.err(883):     at
android.os.Looper.loop(Looper.java:137)
05-16 05:37:36.183: W/System.err(883):     at
android.app.ActivityThread.main(ActivityThread.java:5041)
05-16 05:37:36.193: W/System.err(883):     at
java.lang.reflect.Method.invokeNative(Native Method)
05-16 05:37:36.193: W/System.err(883):     at
java.lang.reflect.Method.invoke(Method.java:511)
05-16 05:37:36.203: W/System.err(883):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-16 05:37:36.213: W/System.err(883):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-16 05:37:36.213: W/System.err(883):     at
dalvik.system.NativeStart.main(Native Method)


Thanks and with regards
Ranjeet Kumar


On Wed, May 15, 2013 at 6:34 PM, Pieter Hintjens <ph at imatix.com> wrote:

> On Wed, May 15, 2013 at 11:11 AM, Ranjeet Kumar <xs2ranjeet at gmail.com>
> wrote:
>
> > Thanks for your reply.
> > But does it mean that we can't use ZeroMQ/JZMQ in Android?
>
> You can use it, and many people do, but building it has always been
> tricky because the toolchain is complex and changes over time.
>
> > when  i tried to run this part of code
> > ZMQ.Socket socket = context.socket(ZMQ.REQ);
> >            socket.connect ("tcp://localhost:5555");
> > I am getting a runtime exception.
>
> Sounds like "localhost" isn't resolving; try 127.0.0.1.
>
> -Pieter
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130516/1e9dc2ae/attachment.htm>


More information about the zeromq-dev mailing list