Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在jeromq中使用轮询_Android_Zeromq_Jeromq - Fatal编程技术网

Android 在jeromq中使用轮询

Android 在jeromq中使用轮询,android,zeromq,jeromq,Android,Zeromq,Jeromq,我正在学习在android中使用zeromq轮询。我在android程序(客户端)中轮询一个req套接字和一个子套接字。这样,该客户端既可以接收来自服务器的回复消息,也可以接收已发布的消息 我的投票不起作用。req套接字和发布套接字均未轮询。如果我不使用轮询,两个套接字都会接收消息 我试着在网上搜索,但找不到任何相关的东西。 客户端代码如下所示: public void run() { ZMQ.Context context = ZMQ.context(1); ZM

我正在学习在android中使用zeromq轮询。我在android程序(客户端)中轮询一个req套接字和一个子套接字。这样,该客户端既可以接收来自服务器的回复消息,也可以接收已发布的消息

我的投票不起作用。req套接字和发布套接字均未轮询。如果我不使用轮询,两个套接字都会接收消息

我试着在网上搜索,但找不到任何相关的东西。 客户端代码如下所示:

    public void run()
   {
    ZMQ.Context context = ZMQ.context(1);
    ZMQ.Socket reqsocket = context.socket(ZMQ.REQ);
    ZMQ.Socket subsocket =context.socket(ZMQ.SUB);
    reqsocket.connect("tcp://10.186.3.174:8081");
    subsocket.connect("tcp://10.186.3.174:8083");
    subsocket.subscribe("".getBytes());
    byte[] receivedmessage;
    Poller poller=context.poller();
    poller.register(reqsocket,Poller.POLLIN);
    poller.register(subsocket,Poller.POLLIN);

    reqsocket.send(msg.getBytes(),0); 

    while(!Thread.currentThread().isInterrupted())
     {

        if(poller.pollin(0))
        {
            receivedmessage=s.recv(0);

        }
          if(poller.pollin(0))
          {
            receivedmessage=subsocket.recv(0);

          }
   }
    s.close();
    context.term();
}


我是错过了什么还是做错了什么

这似乎有三个问题。 主要的一点是,您需要调用
poller.poll()
,作为
while
循环中的第一件事。这就是为什么你没有收到任何消息

下一个问题是,您正在为两个套接字检查相同的索引:我希望第二个
if
语句需要

if(poller.pollin(1))

最后,req套接字需要在每次接收之前发送,因此发送调用需要在while循环中,在刚才添加的poller.poll()之前进行:)

我如何在android中使用jeromq?和JavaSE一样吗?我在想怎么做,结果一无所获。