How to use the ws.connect function in ws

To help you get started, we’ve selected a few ws examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NetEase / pomelo-rpc / lib / rpc-client / mailboxes / ws2-mailbox.js View on Github external
pro.connect = function(tracer, cb) {
  tracer && tracer.info('client', __filename, 'connect', 'ws-mailbox try to connect');
  if (this.connected) {
    tracer && tracer.error('client', __filename, 'connect', 'mailbox has already connected');
    cb(new Error('mailbox has already connected.'));
    return;
  }

  this.socket = wsClient.connect('ws://' + this.host + ':' + this.port);
  //this.socket = wsClient.connect(this.host + ':' + this.port, {'force new connection': true, 'reconnect': false});

  var self = this;
  this.socket.on('message', function(data, flags) {
    try {
      // console.log("ws rpc client received message = " + data);
      var msg = data;

      msg = JSON.parse(msg);

      if (msg.body instanceof Array) {
        processMsgs(self, msg.body);
      } else {
        processMsg(self, msg.body);
      }
    } catch (e) {
github pablojorge / price-tracker / test / requests.js View on Github external
it('should connect', function (done) {
        connection = ws.connect(url);
        connection.on('open', function () {
            done();
        });
    });
github mqttjs / create-stream-server / tests.js View on Github external
s.listen(function(){
      var c = ws.connect('wss://localhost:9004', function(){
        c.send('A');
      });
    });
  });
github mqttjs / create-stream-server / tests.js View on Github external
s.listen(function(){
      var c = ws.connect('ws://localhost:9003', function(){
        c.send('A');
      });
    });
  });
github facebook / react-devtools / shells / electron / node / index.js View on Github external
window.connectToSocket = function () {
  var socket = ws.connect('ws://localhost:8081/devtools');
  socket.onmessage = evt => {
    if (evt.data === 'attach:agent') {
      initialize(socket);
    }
  };
  socket.onerror = function (err) {
    onDisconnected();
    console.log('Error with websocket connection', err);
  };
  socket.onclose = function () {
    onDisconnected();
    console.log('Connection to RN closed');
  };
}
github Silk-GUI / Silk / apps / tunnelclient / Tunnel2Proxy_com.js View on Github external
}catch(e){
      that.proxyServer.destroy();
      console.log(e);
      console.log(data);
      return;
    }
    if(data.name === "id"){
      cb(void(0),data.data);
      console.log("your servers name is: "+data.data)
    }else{
      console.log('received data: ' + data);
      that.handleSocketMessage(data);
    }
  })
  console.log('connecting websocket');
  this.proxyWS = ws.connect("ws://localhost:3000/ws/websocket",function(){
    console.log("connected as websocket: "+arguments)
  });
  this.proxyWS.on("error",function(e){
    console.log('ws error');
    console.log(e.stack);
  })
  this.proxyWS.on("message",function(data){
    console.log('ws message: ' + data);
    that.proxyServer.write(data+"\u00B6");
  })
}
github turbolent / ralph / core / ralph / repl / node-evaluator.js View on Github external
($module)['connect-to-interactor'] = B8['%make-method']('connect-to-interactor', function B97(evaluator__98, url__99) {
    var connection__100 = B69['connect'](url__99);
    {
        B8['get-setter'](evaluator__98, 'connection', connection__100);
        {
            var B101 = connection__100;
            {
                var B102 = 'message';
                {
                    var B103 = B8['curry'](B68['handle-message'], evaluator__98);
                    return(B101['on'](B102, B103));
                }
            }
        }
    }
}, false, ($module)[''], ($module)['connect-to-interactor']);
{
github pablojorge / price-tracker / app / plugins / CexIO.js View on Github external
function CexIOStreamer(symbol, callback, errback) {
    var self = this;

    this.socket = ws.connect('wss://ws.cex.io/ws');

    this.socket.on('open', function (data) {
        self.socket.send(JSON.stringify({
            e: "subscribe",
            rooms: ["tickers"]
        }));
    });

    this.socket.on('message', function (message){
        var payload = JSON.parse(message);
        if ((payload.e !== "tick") ||
            (payload.data.symbol2 !== 'USD')) {
            return;
        }

        if ((payload.data.symbol1 === 'LTC' && symbol === 'LTCUSD') ||

ws

Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js

MIT
Latest version published 6 months ago

Package Health Score

89 / 100
Full package analysis