javascriptzeromqzyre

Zeromq server in javascript, not possible?


I'm trying to create an interface in javascript to talk to and control robots (written in C) using zeromq. I'm new to zeromq and have great difficulty in finding a library to use zeromq in javascript, while a good library exist in numerous other languages. The two small libraries I have found use a workaround using flash or web sockets which makes it a lot more complicated. Both are 'in beta' and abandoned.

The reason we're using html/javascript is because it can be used on many platforms, but it seems like javascript is not made for this kind of job? I feel that I'm doing someone wrong since I find so little information about this. I'm told to use CZMQ and Zyre, but those can't be used with javascript as far as I'm aware? Any help or redirect towards a guide would be appreciated, I'm way in over my head and am making little process.


Solution

  • If I understand your question, you've written an HTML file that you open locally in your browser, and you want your browser to communicate directly to your robot using ZMQ.

    The browser only has two mechanisms with which to connect to an external device or service: HTTP (normal links, forms, AJAX) and web sockets. ZMQ would have to live on top of web sockets. There may be a way to get that working, but it's probably not your ideal set up. Typically you would instead set up a separate web server that serves up your web page. Then you use websockets, ajax, or normal http calls to connect and send info to your webserver, and you use your language of choice to connect to your bot through ZMQ.

    If you use that method, then you can indeed use javascript with ZMQ on the server side, using node.js. You can also use any other server side language that you choose to do the same thing, most of them have ZMQ bindings.

    Your other option, as you've seen, is to use HTTP or web sockets to connect directly to your bot. Either one would work fine, depending on the specifics of your bot, but it wouldn't be my first choice.