0

I am trying to run Zeromq java program in windows 10 OS. To set up the environment I tried to do the following.

1) Download and install the java library for ZMQ from here http://zeromq.org/distro:microsoft-windows.

2) Add the path in the environmental variables.

3) Tried to run the simple Hello World code from zguide.

Server:

import org.zeromq.ZMQ;

public class Hwserver {

public static void main(String[] args) throws Exception {
    ZMQ.Context context = ZMQ.context(1);

    //  Socket to talk to clients
    ZMQ.Socket responder = context.socket(ZMQ.REP);
    responder.bind("tcp://*:5555");

    while (!Thread.currentThread().isInterrupted()) {
        // Wait for next request from the client
        byte[] request = responder.recv(0);
        System.out.println("Received " + new String (request));

        // Do some 'work'
        Thread.sleep(1000);

        // Send reply back to client
        String reply = "World";
        responder.send(reply.getBytes(), 0);
    }
    responder.close();
    context.term();
}
}

Client:

import org.zeromq.ZMQ;

public class Hwclient {

public static void main(String[] args) {
    ZMQ.Context context = ZMQ.context(1);

    //  Socket to talk to server
    System.out.println("Connecting to hello world server…");

    ZMQ.Socket requester = context.socket(ZMQ.REQ);
    requester.connect("tcp://localhost:5555");

    for (int requestNbr = 0; requestNbr != 10; requestNbr++) {
        String request = "Hello";
        System.out.println("Sending Hello " + requestNbr);
        requester.send(request.getBytes(), 0);

        byte[] reply = requester.recv(0);
        System.out.println("Received " + new String(reply) + " " + requestNbr);
    }
    requester.close();
    context.term();
}
}

When I tried to compile the server I got the following error.

error: cannot find symbol import org.zeromq.ZMQ; 

After that I tried to install the library manually. I did the following.

1) Downloaded and unzipped Libzmq-master and jzmq-master from Github.

2) Using Visual Studio 2017 tried to build libzmq.sln & msvc.sln from the directory here

libzmq - libzmq-master\builds\deprecated-msvc\vs2017\libzmq.sln

jzmq - jzmq-master\jzmq-jni\builds\msvc\msvc.sln

But couldn't able to build it. Finding several errors. For example:

libzmq - #error: None of the ZMQ_IOTHREAD_POLLER_USE_* macros defined (compiling source file ........\src\client.cpp) libzmq c:\users\shiha\downloads\libzmq-master\src\poller.hpp

jzmq - Cannot open include file: 'zmq.h': No such file or directory

I am not getting what I am doing wrong. I have followed the guide provided in zeromq.org and also searched for the similar problem. But couldn't able to find the solution.

Sameye
  • 1
  • 2
  • Did you put zmq jar on classpath? – sagarr Oct 12 '18 at 17:42
  • Yes I did. I added a classpath C:\Program Files (x86)\ZeroMQ 4.0.4\bin to my environmental variable. – Sameye Oct 12 '18 at 18:03
  • I kind of understand that I have missed one or more steps. I am not getting what I missed. – Sameye Oct 12 '18 at 18:59
  • To use `jzmq`, you need to have installed libzmq, then you need to build `jzmq` library for windows and finally you need the get the java bindings. Alternatively, just use `jeromq`, because it does not require all the native components such as `jzmq` or `libzmq`. – smac89 Oct 26 '19 at 10:13

0 Answers0