How to use the websocket.client function in websocket

To help you get started, we’ve selected a few websocket 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 jesusprubio / bluebox-ng / utils / steroidsSocket.js View on Github external
'WS' : function () {
                var addr = self.transport.toLowerCase() +
                    '://' + self.target + ':' + self.port;

                if (self.wsPath) {
                    addr += '/' + self.wsPath;
                }
                self.megaSocket = new WebSocketClient({
                    tlsOptions   : {
                        rejectUnauthorized : false
                    }
                });

                setTimeout(timeoutCb, self.timeout);

                self.megaSocket.on('connectFailed', function (err) {
                    received = true; // to avoid the launch of our timeout error
                    if (!wsError) {
                        self.emit('error', {
                            type : 'socket: connectFailed',
                            data : err.toString()
                        });
                    }
                });
github Azure / azure-relay-node / hyco-websocket / lib / HybridConnectionsWebSocketServer.js View on Github external
if (typeof server.config.token === 'function') {
            // server.config.token is a function, call it periodically to renew the token
            tokenRenewDuration = new moment.duration(1, 'hours');
            token = server.config.token();
        } else {
            // server.config.token is a string, the token cannot be renewed automatically
            token = server.config.token;
        }

        headers = { 'ServiceBusAuthorization': token };
    };

    // This represents the token renew timer/interval, keep a reference in order to cancel it.
    var tokenRenewTimer = null;

    var client = new WebSocketClient();
    client.connect(server.listenUri, null, null, headers);
    client.on('connect', function(connection) {
        server.controlChannel = connection;
        server.controlChannel.on('error', function(event) {
            server.emit('error', event);
            clearInterval(tokenRenewTimer);
            if (!closeRequested) {
                connectControlChannel(server);
            }
        });

        server.controlChannel.on('close', function(event) {
            clearInterval(tokenRenewTimer);
            if (!closeRequested) {
                // reconnect
                connectControlChannel(server);
github bkanber / Slackadaisical / src / SlackAPI.js View on Github external
connectRTM() {
        this.rtm = new WebSocketClient();

        this.get('rtm.connect', {}, (err, resp, body) => {
            if (err || !body.ok) {
                this.screen.log("API: rtm.connect failed");
                this.screen.log(err);
                this.screen.log(body);
                console.log("Failed connecting to slack. See log for details.");
                process.exit(1);

                return;
            }

            this.rtm.on('connect', (connection) => {

                connection.on('error', function(error) {
                    console.log("Connection Error: " + error.toString());
github brownplt / pyret-lang / src / server / client-lib.js View on Github external
function start(options) {

  const client = new WebSocketClient();

  const serverModule = options.client.compiler;

  const pidFile = ".pyret-parley." + options.client.port + ".pid";

  function shutdown() {
    try {
      const pid = Number(fs.readFileSync(pidFile));
      fs.unlinkSync(pidFile);
      process.kill(pid, 'SIGINT');
      console.log("Sent kill signal to " + pid);
    }
    catch(e) {
      console.log("No process to quit: " + e);
    }
  }
github IoTKETI / Mobius / mobius / responder.js View on Github external
function request_noti_ws(nu, bodyString, bodytype, xm2mri) {
    var bodyStr = '';

    var WebSocketClient = require('websocket').client;
    var ws_client = new WebSocketClient();

    if(bodytype == 'xml') {
        ws_client.connect(nu, 'onem2m.r2.0.xml');
    }
    else if(bodytype == 'cbor') {
        ws_client.connect(nu, 'onem2m.r2.0.cbor');
    }
    else {
        ws_client.connect(nu, 'onem2m.r2.0.json');
    }

    ws_client.on('connectFailed', function (error) {
        console.log('[nonblocking-async-ws] Connect Error: ' + error.toString());
        ws_client.removeAllListeners();
    });
github momocow / node-cq-websocket / src / transport / ws / node / WebSocketNodeClient.ts View on Github external
public open (): void {
    TransportReadyState.assert(this.state, [
      TransportReadyState.INIT,
      TransportReadyState.CLOSED
    ])

    const client = new WebSocketClient({
      fragmentOutgoingMessages: false,
      ...this.config.clientOptions
    }).once('connect', (connection: WebSocketConnection) => {
      connection.on('message', (msg) => {
        TransportMessage.assert(msg)
        this.emit('message', msg.utf8Data || '')
      }).on('error', (err) => {
        this.emit('error', new ConnectionError(err))
      }).on('close', (code, reason) => {
        this.setState(TransportReadyState.CLOSED)
        this.emit('close', code, reason)
        if (code !== 1000) {
          this.lifeCycle.emit('reconnect')
        }
      })
      this.setState(TransportReadyState.OPEN, connection)
github sensepost / wsproxy / wsproxy.js View on Github external
createClient = function(proto, host, request, origin, connection){
    var preRequests = [];

    //temporary handler for Client<->Proxy connection to catch requests that come before Proxy<->Server session established
    connection.on('message', function(d){
        preRequests.push(d);
        processor.saveOutgoing(request.resourceURL.path,d);
        if (verbose) {doLog(['Received premature request from Client<->Proxy connection:',d.type,d.binaryData,d.utf8Data])}
    })


    var client = new WebSocketClient();
    client.connect(proto+host+request.resourceURL.path, null,origin,request.httpRequest.headers);


    client.on('connectFailed',function(error){
            doLog(['Connect failed!!!!!!']);
            doLog([error])
    })

    client.on('httpResponse', function(response, webSocketClient){
        if (verbose) {
            doLog(['Received non 101 httpResponse']);
            doLog([response.headers,response.statusCode,response.statusMessage]);
        }
    })

    client.on('connect',function(clconn){
github ascetictoolbox / ascetictoolbox / paas / application-monitor.removeme / etc / old / cube / lib / cube / emitter-ws.js View on Github external
function open() {
    timeout = 0;
    close();
    util.log("opening socket: " + url);
    var client = new websocket.client();
    client.on("connect", function(connection) {
      socket = connection;
      socket.on("message", log);
      socket.on("error", reopen);
      socket.on("close", reopen);
      flush();
      if (closing) closeWhenDone();
    });
    client.on("connectFailed", reopen);
    client.on("error", reopen);
    client.connect(url);
  }
github square / cube / lib / cube / emitter-ws.js View on Github external
function open() {
    timeout = 0;
    close();
    metalog.warn('cube_emitter', {is: 'opening socket', url: url});
    var client = new websocket.client();
    client.on("connect", function(connection) {
      socket = connection;
      socket.on("message", log);
      socket.on("error", reopen);
      socket.on("close", reopen);
      flush();
      if (closing) closeWhenDone();
    });
    client.on("connectFailed", reopen);
    client.on("error", reopen);
    client.connect(url);
  }
github Criptext / Criptext-Email-React-Client / electron_app / src / socketClient.js View on Github external
const start = ({ jwt }) => {
  client = new WebSocketClient();
  client.connect(`${SOCKET_URL}?token=${jwt}`, 'criptext-protocol');

  client.on('connectFailed', error => {
    if (shouldReconnect) {
      reconnect();
    }
    log(error);
  });

  client.on('connect', connection => {
    socketConnection = connection;
    log('Socket connection opened');

    connection.on('error', error => {
      reconnect();
      log(error);