1

I am trying to install ZeroMQ on my PC but I can not make my program run without crashing.
The installation:

1) install Visual Studio 2017.

2) clone from git jzmq and libzmq

3) install ZMQ version 4.0.4 for windows.

4) run the script build in: \libzmq\builds\msvc\build\build.bat

5) open in Visual Studio 2017: libzmq\builds\msvc\vs2017\libzmq.sln and jzmq\jzmq-jni\builds\msvc\msvc.sln.

6) rebuild in the Visual Studio 2017 the sln files:

+ libzmq.sln : in the properties: configuration: Active(DebugDLL) platform: Active(x64)

+ msvc.sln : in the properties: configuration:Release platform: Active(x64)
label VC++ Directories: update the include directories and Library directories,
label Linker -> Input: update the Additional Dependencies with - C:\git-repo\libzmq\bin\x64\Debug\v141\dynamic\libzmq.lib;%(AdditionalDependencies)

7) put the libzmq.dll and the jzmq.dll in the system32 folder.

After I finished with the installation, I try to run simple Java example to see if everything is working:
the java code:

import org.zeromq.ZMQ;
import java.nio.charset.Charset;

public class TestMainClass {

public static void main(String[] args){
    try {
        ZMQ.Context context = ZMQ.context(1);
        ZMQ.Socket replier = context.socket(ZMQ.REP);
        replier.bind("tcp://*:5559");

        while (true) {

            String gwSource = replier.recvStr(Charset.defaultCharset());
            replier.send("OK");
            System.out.println(gwSource);
        }
    }catch (Throwable e) {
        System.out.println(e);
    }
  }
}

import org.zeromq.ZMQ;

public class Requester {

public static void main(String[] args){
    ZMQ.Context context = ZMQ.context(1);
    ZMQ.Socket replier = context.socket(ZMQ.REQ);
    replier.connect("tcp://localhost:5559");

    while (true) {
        replier.send("public");
        System.out.println(new String(replier.recv()));
    }
  }
}

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>

<groupId>com.test.hagar</groupId>
<artifactId>hagarTestRealTick</artifactId>
<version>current-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>org.zeromq</groupId>
        <artifactId>jzmq</artifactId>
        <version>3.1.0</version>
    </dependency>
</dependencies>

</project>

the consul output:

for TestMainClass :

"C:\Program Files\Java\jdk1.8.0_121\bin\java" -Xcheck:jni -verbose:jni "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.1\lib\idea_rt.jar=57531:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar;C:\Program Fil
WARNING in native method: JNI call made without checking exceptions when required to from CallLongMethodV
at org.zeromq.ZMQ$Socket.construct(Native Method)
at org.zeromq.ZMQ$Socket.<init>(ZMQ.java:1719)
at org.zeromq.ZMQ$Context.socket(ZMQ.java:451)
at TestMainClass.main(TestMainClass.java:11)
[Dynamic-linking native method org.zeromq.ZMQ$Socket.bind ... JNI]
[Dynamic-linking native method org.zeromq.ZMQ$Socket.recv ... JNI]

Process finished with exit code -1073740791 (0xC0000409)

for Requester :

[Registering JNI native method java.lang.System.arraycopy]
[Dynamic-linking native method java.lang.Thread.registerNatives ... JNI]
[Registering JNI native method java.lang.Thread.start0]
WARNING in native method: JNI call made without checking exceptions when required to from CallLongMethodV
at org.zeromq.ZMQ$Socket.construct(Native Method)
at org.zeromq.ZMQ$Socket.<init>(ZMQ.java:1719)
at org.zeromq.ZMQ$Context.socket(ZMQ.java:451)
at Requester.main(Requester.java:8)
[Dynamic-linking native method org.zeromq.ZMQ$Socket.connect ... JNI]
[Dynamic-linking native method org.zeromq.ZMQ$Socket.send ... JNI]  
[Dynamic-linking native method org.zeromq.ZMQ$Socket.recv ... JNI]

the program crash after the TestMainClass try to receive a response and print: Process finished with exit code -1073740791 (0xC0000409)

I think something is wrong in the installation that causes the fail, but I can not find the problem.

user3666197
  • 1
  • 6
  • 50
  • 92
Hagar Tal
  • 143
  • 2
  • 13
  • Would you mind to put a line **`System.out.println( + ZMQ.Error );`** after each SLOC so as to map the flow of code-execution and isolate a last / suspect call before the reported crash appears? – user3666197 Aug 15 '17 at 11:58
  • are sure to add System.out.println( + ZMQ.Error ); ? ZMQ.Error is a enum.. the code crash after this line: String gwSource = replier.recvStr(Charset.defaultCharset()); in TestMainClass – Hagar Tal Aug 15 '17 at 13:25
  • Principally yes, syntactically adapt to match your code practices. – user3666197 Aug 15 '17 at 13:26
  • I don't understand what do you mean.. the program crash without any java error, it crash while trying to receive a response. i run the code with -Xcheck:jni -verbose:jni flags. this flags didn't print any error as well. – Hagar Tal Aug 15 '17 at 14:53

1 Answers1

0

Ok, the Alea Acta Est:

How about debugging the root-cause?

Level 0: Send first just int-s, instead of any string-s ( where having different add-on charset-issues )

Level 1: try the non-blocking mode of the .recv() method ( where a return from a non-blocking mode of the .recv() method call will finally prove the ZeroMQ-part is not the problem )

user3666197
  • 1
  • 6
  • 50
  • 92
  • i change the String gwSource = replier.recvStr(Charset.defaultCharset()); to byte[] gwSource = replier.recv(); in TestMainClass and replier.send("public"); to replier.send("1"); in the Requester class. and i got the same behavior. crashing while waiting to the response and print: Process finished with exit code -1073740791 (0xC0000409). my feeling is that the problem connected to the C code the the ZMQ is running. – Hagar Tal Aug 15 '17 at 15:24
  • How did **Level 0:** test finish with `: replier.send( 0 ); ... replier.recv() ...;` and `: int gwInt = replier.recv(); replier.send( 1 );` ? – user3666197 Aug 15 '17 at 18:23
  • i can not send replier.send( 0 ) the send method expect a String. and replier.recv() returning byte[]... so i am not sure what changes you whant me to do with the code.. – Hagar Tal Aug 16 '17 at 06:22
  • With all due respect, I do not want you to do anything. Just tried to navigate you closer to the native API, so as to isolate the root-cause of the problem, in case your actual java-binding has troubles to re-represent the ZeroMQ native services for your language environment. – user3666197 Aug 16 '17 at 06:26
  • sorry, i express my self not in the best way.. i am trying to get root-cause of the problem. I am trying to implement your advice to see if it give new info. but i am not sure what you meant by replier.send( 0 ) and int gwInt = replier.recv() – Hagar Tal Aug 16 '17 at 06:36