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

README.md

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

Something went wrong with that request. Please try again.