Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: matias s..
Added: Nov 4, 2019 3:46 AM
Views: 8
  1. const WebSocket = require('ws');
  2. console.log(process.argv);
  3.  
  4. const ws = new WebSocket('ws://localhost:8443/wss2/' + process.argv[2] + '?clientId=' + process.argv[3] + '&operatorId=1');
  5.  
  6. ws.on('open', function open() {
  7.     ws.send('something');
  8. });
  9.  
  10. ws.on('message', function incoming(data) {
  11.     //let demora = Math.round(Math.random() * (10 - 1) + 1);
  12.     let demora = process.argv[4];
  13.     console.log(data);
  14.     console.log('Enviando demora de ' + demora);
  15.     ws.send(JSON.stringify({
  16.         demora: demora,
  17.         clientId: process.argv[3]
  18.     }));
  19.  
  20. });
  21. ws.on('error', function (e) {
  22.  
  23.     console.log(e);
  24. });
Comments disabled