Sha256: 88720b447fde9a0f4d5747914e0891eba0d887564a40a24e793f18de7895af5b

Contents?: true

Size: 1.36 KB

Versions: 19

Compression:

Stored size: 1.36 KB

Contents

var express             = require('express');
var sockjs              = require('sockjs');

var websocket_multiplex = require('websocket-multiplex');


// 1. Setup SockJS server
var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
var service = sockjs.createServer(sockjs_opts);


// 2. Setup multiplexing
var multiplexer = new websocket_multiplex.MultiplexServer(service);

var ann = multiplexer.registerChannel('ann');
ann.on('connection', function(conn) {
    conn.write('Ann says hi!');
    conn.on('data', function(data) {
        conn.write('Ann nods: ' + data);
    });
});

var bob = multiplexer.registerChannel('bob');
bob.on('connection', function(conn) {
    conn.write('Bob doesn\'t agree.');
    conn.on('data', function(data) {
        conn.write('Bob says no to: ' + data);
    });
});

var carl = multiplexer.registerChannel('carl');
carl.on('connection', function(conn) {
    conn.write('Carl says goodbye!');
    // Explicitly cancel connection
    conn.end();
});


// 3. Express server
var app = express.createServer();
service.installHandlers(app, {prefix:'/multiplex'});

console.log(' [*] Listening on 0.0.0.0:9999' );
app.listen(9999, '0.0.0.0');

app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});

app.get('/multiplex.js', function (req, res) {
    res.sendfile(__dirname + '/multiplex.js');
});

Version data entries

19 entries across 19 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/sockjs/examples/multiplex/server.js
disco_app-0.18.0 test/dummy/node_modules/sockjs/examples/multiplex/server.js
disco_app-0.18.2 test/dummy/node_modules/sockjs/examples/multiplex/server.js
enju_library-0.3.8 spec/dummy/node_modules/sockjs/examples/multiplex/server.js
ilog-0.4.1 node_modules/sockjs/examples/multiplex/server.js
ilog-0.4.0 node_modules/sockjs/examples/multiplex/server.js
ilog-0.3.3 node_modules/sockjs/examples/multiplex/server.js
jester-data-8.0.0 node_modules/sockjs/examples/multiplex/server.js
ezii-os-5.2.1 node_modules/sockjs/examples/multiplex/server.js
ezii-os-2.0.1 node_modules/sockjs/examples/multiplex/server.js
ezii-os-1.1.0 node_modules/sockjs/examples/multiplex/server.js
ezii-os-1.0.0 node_modules/sockjs/examples/multiplex/server.js
ezii-os-0.0.0.1.0 node_modules/sockjs/examples/multiplex/server.js
ezii-os-0.0.0.0.1 node_modules/sockjs/examples/multiplex/server.js
optimacms-0.4.3 spec/dummy/node_modules/sockjs/examples/multiplex/server.js
optimacms-0.4.2 spec/dummy/node_modules/sockjs/examples/multiplex/server.js
cortex-0.1.3 spec/dummy/node_modules/sockjs/examples/multiplex/server.js
dragonfly_puppeteer-0.1.0 node_modules/sockjs/examples/multiplex/server.js
lanes-0.8.0 node_modules/sockjs/examples/multiplex/server.js