ZeroMQ in javascript client

后端 未结 3 2064
轻奢々
轻奢々 2021-01-31 22:09

Have anyone used ZmqSocket.js successfully? 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 o

相关标签:
3条回答
  • 2021-01-31 22:26

    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).

    What I do right now is have a simple node.js based proxy that uses socket.io to communicate with browsers and pushes data in (and reads from) a zeromq socket, where the rest of the app is.


    Update in 2013: I wrote sockjsproxy, which essentially proxies messages to/from sockjs and zeromq, allowing you to implement the server in any language you want by just implementing the (very simple) ZeroMQ-based protocol.

    I've personally used it with Python and Scala servers to build real-time web apps.

    0 讨论(0)
  • 2021-01-31 22:28

    I started looking into a solution to use a web browser for a 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.

    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).

    I currently have a Python app with a UI using Tk and I plan to replace it with a web interface.

    The problem I have with the ZMQ JavaScript biding is that it uses a flash component, which is not supported by iOS.

    Doing a bit of Googoling I found a post titled "Interacting With ZeroMQ From the Browser" that uses NullMQ

    I hope this helps.

    0 讨论(0)
  • 2021-01-31 22:31

    Another perspective: implementing a WebSocket-to-ZeroMQ proxy that handles all of 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.

    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.

    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.

    0 讨论(0)
提交回复
热议问题