Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple independent connections to a single service from a single client. #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions LICENSE-MIT-SockJS
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (C) 2011 VMware, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,20 @@ Protocol
--------

The underlying protocol is quite simple. Each message consists of
three comma separated parts: _type_, _topic_ and _payload_. There are
four comma separated parts: _type_, _topic_, _id and _payload_. There are
three valid message types:

* `sub` - expresses a will to subscribe to a given _topic_.
* `msg` - a message with _payload_ is being sent on a _topic_.
* `uns` - a will to unsubscribe from a _topic_.

The _topic_ identifies a channel registered on the server side.

The _id_ a unique connection identifier generated on the client side. Each
request to subscribe to a topic from a given client has a unique id.
This makes it possible for a single client to open multiple independent
channel connection to a single server-side service.

Invalid messages like wrong unsubscriptions or publishes to a _topic_
to which a client was not subscribed to are simply ignored.

Expand Down
4 changes: 4 additions & 0 deletions copyright-notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
We got permission from the original author of websocket multiplex to
use the MIT-license. See here:

https://github.com/sockjs/websocket-multiplex/issues/3
67 changes: 67 additions & 0 deletions examples/simul-socks/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*global require setTimeout console SockJS WebSocketMultiplex */

(function () {

var MULTIPLEX = true;
var multiplexer = null;

function getMultiplexer() {
if (!multiplexer) {
var sockjs = new SockJS('/multiplexer');
multiplexer = new WebSocketMultiplex(sockjs);
}
return multiplexer;
}

function createSocket(name) {
if (MULTIPLEX) {
return getMultiplexer().channel(name);
} else {
return new SockJS('/'+name);
}
}

function talkToTheSocket(myName, interval) {
var sock = createSocket('echo');

function log(msg) {
console.log('['+myName+'] '+msg);
}

function send(msg) {
log('>> '+msg);
sock.send(msg);
}

function conversation(i) {
if (i < 10) {
send(myName + " says "+i);
setTimeout(function () {
conversation(i+1);
}, interval);
} else {
sock.close();
setTimeout(function () {
send(myName + 'talking to closed connection, should be dropped');
}, interval);
}
}

sock.onopen = function () {
log(' initiates a conversation');
conversation(0);
};
sock.onmessage = function (e) {
log('<< ' + e.data);
};
sock.onclose = function () {
log(' is leaving');
};

}

//Ann and Bob are talking to the same service at the same time
talkToTheSocket('Bob', 2000);
talkToTheSocket('Ann', 1500);

}());
11 changes: 11 additions & 0 deletions examples/simul-socks/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<title>This page is blank... look in the jsconsole for some output</title>
<script src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script>
<script src="multiplex.js"></script>
<script src="client.js"></script>
</head>
<body>
<p>This page is blank... look in the jsconsole for some output</p>
</body>
8 changes: 8 additions & 0 deletions examples/simul-socks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name" : "websocket-multiplex-sockjs-example",
"version" : "0.0.0-unreleasable",
"dependencies" : {
"express" : "2.5.8",
"sockjs" : "0.3.x"
}
}
Loading