java - Why a .term() of Jeromq blocks infinitely even I have called .close() to close all the sockets? -


i tried use 0.4.2 of jeromq in android app , added compile 'org.zeromq:jeromq:0.4.2' build.gradle, .connect( string addr ) in zmq crash, no matter if server program available.

so tried use 0.4.0 of jeromq , .connect() can work, .term() of jeromq never return when server program not available.

please see simple version of code below in android , following codes run in thread of intent service.

        zmq.context context = zmq.context(1);         zmq.socket client = context.socket(zmq.req);                                client.connect("tcp://192.168.31.10:13587");                    client.send("android");          final int request_timeout = 3000;         zmq.poller items = context.poller(1);         items.register(client, zmq.poller.pollin);         items.poll(request_timeout);                   if (items.pollin(0)) {            string reply = client.recvstr();         }           client.close();         context.term(); 

a call client.connect( "tcp://192.168.31.10:13587" ) method crash, if used 0.4.2 of jeromq. if used version 0.4.0 or 0.3.6, context.term() never returns, when server program did not run.

you happy man, bob!

the why simple - .term()-blocking intended behaviour on sockets, have linger == -1.

just ( yes, always )
setup:

<asocketinstance>.setsockopt( zmq.linger, 0 ); 

for each socket instance, right upon instantiation, , done.

( there many other api-details fine tune, if need setup app become more robust against error or mis-use uncontrollable set of principally distributed agents, due care taken )


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -