javascript javascript客户端中的ZeroMQ
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8145060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ZeroMQ in javascript client
提问by Carlo Pires
Have anyone used ZmqSocket.jssuccessfully? I'd like to know how can it be used to establish a safe channel between the browser and a zeromq server app. Is there other/better options for such use case?
有人成功使用过ZmqSocket.js吗?我想知道如何使用它在浏览器和 zeromq 服务器应用程序之间建立安全通道。这种用例是否有其他/更好的选择?
采纳答案by Emil Ivanov
I've never used ZmqSocket.js, but I can tell you that it's probably not a good idea (yet). This is because zmq still assumes that both peers know the protocol well and will blow up if given invalid data (they are working on fixing that, though).
我从未使用过 ZmqSocket.js,但我可以告诉你,这可能不是一个好主意(目前)。这是因为 zmq 仍然假设两个对等方都非常了解协议,并且如果给定无效数据就会爆炸(不过他们正在努力解决这个问题)。
What I do right now is have a simple node.jsbased proxy that uses socket.ioto communicate with browsers and pushes data in (and reads from) a zeromq socket, where the rest of the app is.
我现在做的是有一个简单的基于node.js的代理,它使用socket.io与浏览器通信并将数据推送到(并从中读取)一个 zeromq 套接字,应用程序的其余部分就在这里。
Update in 2013:I wrote sockjsproxy, which essentially proxies messages to/from sockjsand zeromq, allowing you to implement the server in any language you want by just implementing the (very simple) ZeroMQ-based protocol.
2013 年更新:我编写了sockjsproxy,它基本上代理了sockjs和 zeromq 之间的消息,允许您通过实现(非常简单的)基于 ZeroMQ 的协议以您想要的任何语言实现服务器。
I've personally used it with Python and Scala servers to build real-time web apps.
我个人将它与 Python 和 Scala 服务器一起使用来构建实时 Web 应用程序。
回答by jschiavon
I started looking into a solution to use a web browser for a UI.
我开始研究将 Web 浏览器用于 UI 的解决方案。
I have a Java application that collects information from several sources, analyses it a stores the results in a database, allowing other systems to the information.
我有一个 Java 应用程序,它从多个来源收集信息,对其进行分析并将结果存储在数据库中,从而允许其他系统获取该信息。
The Java app provides information (logs, events, and so on) on a PUSH ZMQ socket and provides a REP socket to control it (changing parameters, diagnosis requests, etc).
Java 应用程序在 PUSH ZMQ 套接字上提供信息(日志、事件等)并提供 REP 套接字来控制它(更改参数、诊断请求等)。
I currently have a Python app with a UI using Tk and I plan to replace it with a web interface.
我目前有一个使用 Tk 的带有 UI 的 Python 应用程序,我计划用 Web 界面替换它。
The problem I have with the ZMQ JavaScript biding is that it uses a flash component, which is not supported by iOS.
我对 ZMQ JavaScript 投标的问题是它使用了 iOS 不支持的 flash 组件。
Doing a bit of Googoling I found a post titled "Interacting With ZeroMQ From the Browser" that uses NullMQ
做一点谷歌搜索,我发现了一篇标题为“从浏览器与 ZeroMQ 交互”的帖子,它使用了NullMQ
I hope this helps.
我希望这有帮助。
回答by Just Jake
Another perspective: implementing a WebSocket-to-ZeroMQ proxy that handles allof ZeroMQ's strategies seems like a lot of work, but you can very quickly get a partial proxy running. Like Emil, I'm experimenting with a PyZMQ <--Tornado--> WebSocket bridge; in my case I only care about getting messages from SUB sockets.
另一个角度:实现一个处理所有ZeroMQ 策略的 WebSocket-to-ZeroMQ 代理似乎需要做很多工作,但您可以很快地运行部分代理。像 Emil 一样,我正在试验 PyZMQ <--Tornado--> WebSocket 桥接器;就我而言,我只关心从 SUB 套接字获取消息。
In my model, I send JSON messages from the browser to the proxy, requesting the creating of new ZMQ sockets. When these sockets receive data, they send it back to the browser over the same WebSocket connection.
在我的模型中,我从浏览器向代理发送 JSON 消息,请求创建新的 ZMQ 套接字。当这些套接字接收到数据时,它们会通过相同的 WebSocket 连接将数据发送回浏览器。
Here's the python proxy backend, and my javascript proxy frontend. In my Python code, the AsyncReciever
class is a very thin wrapper around a ZMQStream
that basically runs JSON encode/decode. If you want to send raw ZeroMQ bytes to the browser, things would be even easier: just connect a ZMQSocket.on_message
callback directly to BridgeWebSocket.write_message
.
这是python 代理后端和我的javascript 代理前端。在我的 Python 代码中,AsyncReciever
该类是一个非常薄的包装器,ZMQStream
它基本上运行 JSON 编码/解码。如果您想将原始 ZeroMQ 字节发送到浏览器,事情会更简单:只需将ZMQSocket.on_message
回调直接连接到BridgeWebSocket.write_message
.