forked from alebedev87/haproxy-timeout-tunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket-cli.js
executable file
·44 lines (36 loc) · 1.24 KB
/
websocket-cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
const host = process.env.HOST || 'localhost';
const port = process.env.PORT || 8080;
const scheme = process.env.SCHEME || 'ws';
const send = process.env.SEND || false;
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
});
client.on('connect', function(connection) {
console.log('WebSocket Client Connected');
connection.on('error', function(error) {
console.log("Connection Error: " + error.toString());
});
connection.on('close', function() {
console.log('echo-protocol Connection Closed');
});
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log("Received: '" + message.utf8Data + "'");
}
});
function sendNumber() {
if (connection.connected) {
var number = Math.round(Math.random() * 0xFFFFFF);
connection.sendUTF(number.toString());
setTimeout(sendNumber, 100000);
}
}
if (send) {
sendNumber();
}
});
client.connect(`${scheme}://${host}:${port}/`, 'echo-protocol');