ZMQ { public static Context context(int ioThreads) { return new Context(ioThreads); }  static int getMajorVersion(); static int getMinorVersion(); static int getPatchVersion(); static int getFullVersion(); static int makeVersion(final int major, final int minor, final int patch); static String getVersionString(); static void proxy(Socket frontend, Socket backend, Socket capture); static int poll(PollItem[] items, long timeout); static int poll(PollItem[] items, int count, long timeout); static Context context(int ioThreads); static final int NOBLOCK; static final int DONTWAIT; static final int SNDMORE; static final int PAIR; static final int PUB; static final int SUB; static final int REQ; static final int REP; static final int DEALER; static final int XREQ; static final int ROUTER; static final int XREP; static final int PULL; static final int PUSH; static final int XPUB; static final int XSUB; static final int STREAM; static final int STREAMER; static final int FORWARDER; static final int QUEUE; @Deprecated
    static final int UPSTREAM; @Deprecated
    static final int DOWNSTREAM; static final int EVENT_CONNECTED; static final int EVENT_CONNECT_DELAYED; static final int EVENT_CONNECT_RETRIED; static final int EVENT_LISTENING; static final int EVENT_BIND_FAILED; static final int EVENT_ACCEPTED; static final int EVENT_ACCEPT_FAILED; static final int EVENT_CLOSED; static final int EVENT_CLOSE_FAILED; static final int EVENT_DISCONNECTED; static final int EVENT_MONITOR_STOPPED; static final int EVENT_ALL; }
@Test public void testSendMoreRequestReplyOverTcp() { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket reply = null; ZMQ.Socket socket = null; try { reply = context.socket(ZMQ.REP); reply.bind("tcp: socket = context.socket(ZMQ.REQ); socket.connect("tcp: socket.send("test1", ZMQ.SNDMORE); socket.send("test2"); assertEquals("test1", reply.recvStr()); assertTrue(reply.hasReceiveMore()); assertEquals("test2", reply.recvStr()); } finally { try { socket.close(); } catch (Exception ignore){} try { reply.close(); } catch (Exception ignore){} try { context.term(); } catch (Exception ignore) {} } }
@Test public void testPollerUnregister() { Context context = ZMQ.context(1); Socket socketOne = context.socket(ZMQ.SUB); Socket socketTwo = context.socket(ZMQ.REP); Poller poller = new ZMQ.Poller(2); poller.register(socketOne, ZMQ.Poller.POLLIN); poller.register(socketTwo, ZMQ.Poller.POLLIN); socketOne.setLinger(0); socketOne.close(); socketTwo.setLinger(0); socketTwo.close(); poller.unregister(socketOne); poller.unregister(socketTwo); context.term(); }
@Test public void testBindToSystemRandomPort() { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket sock = context.socket(ZMQ.DEALER); sock.bindToSystemRandomPort("tcp: sock.close(); }
@Test public void testReqRep() { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket in = context.socket(ZMQ.REQ); in.bind("inproc: ZMQ.Socket out = context.socket(ZMQ.REP); out.connect("inproc: for (int i = 0; i < 10; i++) { byte[] req = ("request" + i).getBytes(); byte[] rep = ("reply" + i).getBytes(); assertTrue(in.send(req, 0)); byte[] reqTmp = out.recv(0); assertArrayEquals(req, reqTmp); assertTrue(out.send(rep, 0)); byte[] repTmp = in.recv(0); assertArrayEquals(rep, repTmp); } }