Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const WebSocket = require('ws');
- var ws, interval, response;
- function connect () {
- console.log('Connecting...')
- clearInterval(interval);
- ws = new WebSocket('wss://fairlay.com/testing/');
- ws.on('close', function (e) { console.log(e); setTimeout(connect, 5000); });
- ws.on('error', function (e) { console.log(e); setTimeout(connect, 5000); });
- ws.on('open', function () {
- response = false;
- console.log("Ignore next response:")
- interval = setInterval(send_and_wait, 5000);
- });
- ws.on('message', function (data) {
- console.log('PONG!');
- response = true;
- });
- }
- function send_and_wait () {
- if (!response) console.log('No response from server');
- else console.log('Everything\'s fine')
- response = false;
- console.log('PING?')
- ws.send('PING');
- }
- connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement