Code Monkey home page Code Monkey logo

jsmq's Introduction

JSMQ

JSMQ is javascript client for ZeroMQ/NetMQ over WebSockets.

ZeroMQ and NetMQ don't have a WebSockets transport at the moment, however extensions already exist for NetMQ and CZMQ.

For browsers without WebSockets support (RFC6455) you can try to use web-socket-js.

Both JSMQ and NetMQ WebSockets are beta at the moment and the API and protocol will probably changed.

The JSMQ currently implement the dealer and subscriber patterns and the NetMQ WebSockets implement the router and publisher patterns.

You can download the JSMQ.JS file from this page or from nuget, just search for JSMQ and include prerelease.

Using JSMQ is very similar to using other high level binding of ZeroMQ. Following is small example:

<html>
    <script src="JSMQ.js"></script>
    <script>
        var dealer = new JSMQ.Dealer();
        dealer.connect("ws://localhost");

        // we must wait for the dealer to be connected before we can send messages, any messages we are trying to send
        // while the dealer is not connected will be dropped
        dealer.sendReady = function() {
            document.getElementById("sendButton").disabled = "";
        };

        var subscriber = new JSMQ.Subscriber();
        subscriber.connect("ws://localhost:81");
        subscriber.subscribe("chat");

        subscriber.onMessage = function (message) {
            
            // we ignore the first frame because it's topic
            message.popString();

            document.getElementById("chatTextArea").value =
                document.getElementById("chatTextArea").value +
                message.popString()  + "\n";
        };

        dealer.onMessage = function (message) {
            // the response from the server
            alert(message.popString());
        };

        function send() {
            var message = new JSMQ.Message();
            message.addString(document.getElementById("messageTextBox").value);
            
            dealer.send(message);
        }
    </script>
    <body>                        
        <textarea id="chatTextArea" readonly="readonly"></textarea>
        <br/>
        <label>Message:</label><input id="messageTextBox" value="" />
        <button id="sendButton" disabled="disabled" onclick="javascript:send();">
            Send
        </button>                    
    </body>
</html>

jsmq's People

Contributors

krisrok avatar leverate-somech avatar mhaberler avatar somdoron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsmq's Issues

Work with ZMQ PHP server

Now I have a ZMQ server that is written in PHP. How can JSMQ work with it? Does it need a websocket server? Please help!

State of development.

Hello there,

I found this project to be particularly interesting and I would like to know more about its current state of development. The README says "Both JSMQ and NetMQ WebSockets are beta at the moment and the API and protocol will probably changed.", and the last commit appears to be 4 months ago. What needs to be done to bring the code to a stable release? Is there a road map formulated somewhere?

Thank you for your time.

message type tag encoding

with the original ZWS spec ws frames are type-tagged with a single character code.

Since the protocol does now assume a binary-safe link, we could use a normal binary int field to represent the ws frame tag. This would for instance allow encoding of bit fields, for instance the ZMQ_MORE flag.

Options I see is:

  • fixed size int (8,16,32..)
  • varint-encoding protobuf style

My personal preference would be the latter. It is well specified, implementation is well understood (all of google protobuf breaks if this breaks), and it is extensible with respect to the size of the value, while being a single byte in the common case.

On varint encoding:
https://developers.google.com/protocol-buffers/docs/encoding
http://stackoverflow.com/questions/19758270/read-varint-from-linux-sockets

the nice part: https://github.com/dcodeIO/ByteBuffer.js/wiki/API already takes care of varint encoding, and base64 if required, so not much to do. Meaning: if we use ByteBuffer.js to encode the ws frames, support is outsourced.

authentication of ZWS sessions

we might want to think through this issue as far as any frame-level support might be required.

While I'm still clueless on the issue, it seems frame-level support might make sense, like in this example: https://github.com/tavendo/AutobahnPython/tree/master/examples/twisted/websocket/auth_persona

I'd see two different scenarios which might be combined eventually:

  • authenticating against the proxy
  • authenticating against Curve

this is still fuzzy - just noting the subject so it isnt lost.

requirement: binary safety of frames

I think any framing/encoding of zeromq frames over websocket transports MUST handle frames binary transparent.

This is a requirement of using code. If the protocol layer can use a particular ws connection in binary-safe mode or not MUST not impact using code.

I think if JSMQ is not to be binary-safe, we could just as well encode a zeromq msg as a JSON object and be done with it. Actually base64 encoding non-binary-safe frames and tagging them as encoded, then sending the whole zmsg_t as a JSON object is an alternative option for the protocol. Not elegant, but workable.

Cant send large strings of 1mb or 2mb size

@somdoron
It seems I can't send large strings like the dom of an HTML page through jsmq, I've tried multiple things, like StringToUint8Array function, slicing the array into pieces which didn't work also...

Any ideas how we can achieve that ??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.