Skip to content
Websocket server - pure JS - no build issues
Find file
Latest commit 2bfb193 @digplan fix
Failed to load latest commit information. fix
package.json fix
test.js fix


Websocket server - extends the excellent

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

// hook connection attempt
svr.hook = function(ws){
    // 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

Something went wrong with that request. Please try again.