jeromq: ZMQ.REQ regression since 0.4.0

I am writing a library that communicates with the ZeroMQ server of OpenNMT. This code works using 0.3.6, but hangs on the receiving using any 0.4.x branch.

    public OpenNMTZeroMQClient(String host, int port) {
        this.context = ZMQ.context(2);
        this.socket = context.socket(ZMQ.REQ);
        String hostAddress = "tcp://" + host + ":" + port;
        LOG.info("Connecting to '{}'", hostAddress);
        socket.connect(hostAddress);
    }


    public void translate(String text) {
        String js = new JSONArray()
                .put(new JSONObject()
                        .put("src", text))
                .toString();
        LOG.info("Sending '{}'...", js);
        boolean wasSent = socket.send(js.getBytes(ZMQ.CHARSET), 0);
        if(wasSent) {
            LOG.info("Sent!");
        }
        LOG.info("Receiving...");
        String reply = socket.recvStr();
        LOG.info("Received: '{}'", reply);
    }

    public void close() {
        if(this.socket != null) {
            this.socket.close();
        }
        if(this.context != null) {
            this.context.term();
        }
    }

It doesn’t actually fail, but it just hangs on the recv() call. The server didn’t receive anything, so the problem is probably that the send never happened.

EDIT: code formatting

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@fredoboulo The 0.4.3 release does indeed fix the issue. Thanks a bunch and sorry for the delay on my end!