socket-server

Websocket server - extends the excellent https://github.com/einaros/ws

npm install socket-server
2 downloads in the last day
11 downloads in the last week
20 downloads in the last month

socket-server

Websocket server - extends the excellent https://github.com/einaros/ws

// same params as ws
var svr = require('./socketserver.js')({port: 8080});

// hook connection attempt
svr.hook = function(ws){
    console.log('hooked');
    // set ws.deny = true to deny connection
    return ws;
}

// list of connected clients
var clients = svr.clientlist;

// send object or string to all clients
svr.sendAll({some: 'thing'});

// send to a particular client id only
svr.send('adsed290', {some: 'thing'});

// send node style error, results
svr.return(null, {name: 'sock'});
  ==> all clients get this {e: null, r: {name:'sock'}}

// do something with messages from clients
svr.onmessage = function(s){
     console.log('yo! ', s);
}

// view debugging info
$ debug=1 myapp.js
npm loves you