简体   繁体   English

ZeroMQ for Node.js是否与Electron兼容?

[英]Is ZeroMQ for Node.js compatible with Electron?

I am have a huge headache from trying to get the ZMQ Node bindings working with Electron, especially on Windows. 试图让ZMQ Node绑定与Electron一起使用,尤其是在Windows上,我感到非常头疼。 I am working on Windows 7 and Ubuntu 16.04 and both of them have two separate issues. 我正在Windows 7和Ubuntu 16.04上工作,它们都有两个单独的问题。

On Windows, I get an error when I try to do require('zmq') 在Windows上,当我尝试执行require('zmq')时出现错误

C:\vueelectron\app\node_modules\bindings\bindings.js:91 Uncaught Error: Could not locate the bindings file. Tried:
 → C:\vueelectron\app\node_modules\zmq\build\zmq.node
 → C:\vueelectron\app\node_modules\zmq\build\Debug\zmq.node
 → C:\vueelectron\app\node_modules\zmq\build\Release\zmq.node
 → C:\vueelectron\app\node_modules\zmq\out\Debug\zmq.node
 → C:\vueelectron\app\node_modules\zmq\Debug\zmq.node
 → C:\vueelectron\app\node_modules\zmq\out\Release\zmq.node
 → C:\vueelectron\app\node_modules\zmq\Release\zmq.node
 → C:\vueelectron\app\node_modules\zmq\build\default\zmq.node
 → C:\vueelectron\app\node_modules\zmq\compiled\6.1.0\win32\x64\zmq.node

I've tried compiling with VS 2013 and 2015, rebuilt multiple times, used electron-rebuild nothing seems to be working. 我尝试使用VS 2013和2015进行编译,多次重建,使用electron-rebuild似乎没有任何效果。

On Linux it loads up fine but the problem is that when I send a message, it seems to get stuck in a loop somewhere and it keeps sending sending hundreds of messages and goes on doing that indefinitely. 在Linux上,它可以很好地加载,但是问题是当我发送一条消息时,它似乎陷入了某个地方的循环中,并且不断发送数百条消息,并且无限期地继续执行此操作。 This was resolved by upgrading from the version of ZMQ in the Ubuntu repositories to the latest one downloaded from the ZeroMQ website. 通过将Ubuntu存储库中的ZMQ版本升级到从ZeroMQ网站下载的最新版本,可以解决此问题。

This is the code I used in my index.html file of my Electron app. 这是我在Electron应用程序的index.html文件中使用的代码。

const electron = require('electron')
const zmq = require('zmq')

const socket = zmq.socket('req')
socket.connect('tcp://10.10.0.51:3111')

socket.on('message', function (data) {
  console.log(socket.identity + ': answer data ' + data)
})

socket.send('test')

Has anyone else been able to get Electron + ZMQ working? 还有其他人能够使Electron + ZMQ工作吗? If so, what is your development enviroment like? 如果是这样,您的开发环境如何? Thanks. 谢谢。

The problem is the unmatched node.js binary that is delivered by Electron and your version of node. 问题是Electron和您的节点版本提供的node.js二进制文件不匹配。 The long answer is that you need to compile Electron and ZeroMQ with the same Node.js headers. 长答案是,您需要使用相同的Node.js标头编译Electron和ZeroMQ。 Here is the response from Electron community http://github.com/electron/electron/issues/6805 . 这是Electron社区http://github.com/electron/electron/issues/6805的回复。 There's a short answer now though! 现在有一个简短的答案!

Use zeromq in place of zmq (same API). 使用zeromq代替zmq (相同的API)。 zeromq provides prebuilt binaries for electron and node.js for OS X, Windows, and macOS/OS X. After installing zeromq , rebuild for the version of electron you're using: zeromq为OS X,Windows和macOS / OS X提供了针对electronic和node.js的预编译二进制文件。安装zeromq ,针对您使用的电子版本进行重建:

npm rebuild zeromq --runtime=electron --target=1.4.5

Thanks to the zeromq.js team and have fun with ZeroMQ! 感谢zeromq.js团队,并与ZeroMQ一起玩得开心!

It might be safer to put access to your queue behind an api layer. 将对队列的访问权限放在api层后面可能更安全。 You might have better success with stability too, native modules in electron can be very tricky. 您可能还会在稳定性方面取得更好的成功,电子中的本机模块可能会非常棘手。

And but that I mean have a REST server which your electron application communicates with. 但是,我的意思是拥有一个与您的电子应用程序进行通信的REST服务器。 It would send a message to that api, which then queues the message for your application. 它将向该api发送一条消息,然后该api将消息排队给您的应用程序。 Restrict access to the queue at the network level to only the api server. 将网络级别的队列访问权限限制为仅api服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM