lib/ws.js
function ws(argv, callback) {
  if (!argv[2]) {
    console.error("url is required");
    console.error("Usage : ws <url>");
    process.exit(-1);
  }
  var uri = argv[2];
  var updatesVia = 'wss://' + uri.split('/')[2] + '/';

  var s;

  var connect = function(){
    s = new wss(updatesVia, {
      origin: 'http://websocket.org'
    });

    s.on('error', function() {
      callback('socket error');
      setTimeout(connect, RECONNECT);
    });

    s.on('open', function open() {
      var sub = 'sub ' + uri;
      callback(null, sub);
      s.send(sub);

      // periodically ping server
      setInterval(function() {
        var message = 'ping';
        debug(null, message);
        s.send(message);
      }, INTERVAL);
    });

  };
  connect();

  s.on('message', function message(data, flags) {
    callback(null, data);
  });

}
function ws(argv, callback) {
  if (!argv[2]) {
    console.error("url is required");
    console.error("Usage : ws <url>");
    process.exit(-1);
  }
  var uri = argv[2];
  var updatesVia = 'wss://' + uri.split('/')[2] + '/';

  var s;

  var connect = function(){
    s = new wss(updatesVia, {
      origin: 'http://websocket.org'
    });

    s.on('error', function() {
      callback('socket error');
      setTimeout(connect, RECONNECT);
    });

    s.on('open', function open() {
      var sub = 'sub ' + uri;
      callback(null, sub);
      s.send(sub);

      // periodically ping server
      setInterval(function() {
        var message = 'ping';
        debug(null, message);
        s.send(message);
      }, INTERVAL);
    });

  };
  connect();

  s.on('message', function message(data, flags) {
    callback(null, data);
  });

}
function ws ( argv , callback ) { if ( ! argv [ 2 ] ) { console . error ( "url is required" ) ; console . error ( "Usage : ws <url>" ) ; process . exit ( - 1 ) ; } var uri = argv [ 2 ] ; var updatesVia = 'wss://' + uri . split ( '/' ) [ 2 ] + '/' ; var s ; var connect = function ( ) { s = new wss ( updatesVia , { origin : 'http://websocket.org' } ) ; s . on ( 'error' , function ( ) { callback ( 'socket error' ) ; setTimeout ( connect , RECONNECT ) ; } ) ; s . on ( 'open' , function open ( ) { var sub = 'sub ' + uri ; callback ( null , sub ) ; s . send ( sub ) ; // periodically ping server setInterval ( function ( ) { var message = 'ping' ; debug ( null , message ) ; s . send ( message ) ; } , INTERVAL ) ; } ) ; } ; connect ( ) ; s . on ( 'message' , function message ( data , flags ) { callback ( null , data ) ; } ) ; }
ws runs a websocket against a URI

@param {String} argv[2] url
@callback {bin~cb} callback
ws runs a websocket against a URI