-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumer.js
More file actions
49 lines (37 loc) · 1.03 KB
/
Copy pathConsumer.js
File metadata and controls
49 lines (37 loc) · 1.03 KB
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
45
46
47
48
49
module.exports = function(){
var net = require('net');
var serverAddress = '0.0.0.0';
var serverPort = 10000;
// Gen k value
var k = Math.floor(Math.random()*13);
var iIDArray = []
console.log(k + " keepAlive's");
var consumer = net.createConnection(serverPort, serverAddress, function(){
consumer.on('data', function(data){
var type = data.toString().slice(0,1);
//console.log(type);
if (type == 0){
console.log(data.toString().slice(1, data.length));
}
else if (type == 1){
console.log(data.toString().slice(1, data.length));
clearInterval(iIDArray[0]);
}
});
});
// Sends initial registration message
var register = '0'
consumer.write(register);
//Manage sending of keep alive messages
var i = 0;
iID = setInterval(function(){
var keepAlive = '1';
// sends k keep alive messages
if (i < k){
//console.log("keepAlive sent")
consumer.write(keepAlive);
}
i++
}, 5000);
iIDArray.push(iID);
}