我正在尝试在我的PC上安装ZeroMQ,但我无法让我的程序在不崩溃的情况下运行。
安装:
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: libzmqbuildsmsvcbuildbuild.bat
5) open in Visual Studio 2017: libzmqbuildsmsvcvs2017libzmq.sln and jzmqjzmq-jnibuildsmsvcmsvc.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-repolibzmqbinx64Debugv141dynamiclibzmq.lib;%(AdditionalDependencies)
7) put the libzmq.dll and the jzmq.dll in the system32 folder.
完成安装后,我尝试运行简单的 Java 示例以查看一切是否正常工作:java 代码:
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>
领事输出:
对于测试主类:
"C:Program FilesJavajdk1.8.0_121binjava" -Xcheck:jni -verbose:jni "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2017.2.1libidea_rt.jar=57531:C:Program FilesJetBrainsIntelliJ IDEA Community Edition 2017.2.1bin" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_121jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_121jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_121jrelibextaccess-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)
对于请求者:
[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]
程序在测试主类尝试接收响应并打印后崩溃: 进程已完成,退出代码为 -1073740791 (0xC0000409(
我认为安装中有问题导致失败,但我找不到问题。
好的,Alea Acta Est:
如何调试根本原因?
级别 0:首先发送int
-s,而不是任何string
-s(具有不同的附加字符集问题(
级别 1:尝试.recv()
方法的非阻塞模式(其中从.recv()
方法调用的非阻塞模式返回最终将证明 ZeroMQ 部分不是问题(