-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
80 lines (54 loc) · 1.67 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var http = require('http');
var fs = require('fs');
var config = require('./config');
var convert = require('./convertImage');
function request(data, callback) {
// An object of options to indicate where to post to
var post_options = {
host: config.rushHost || '192.168.1.84',
port: config.rushUnsecPort || 5001,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-relayer-host' : config.endpoint + ':' + config.endpointPort
}
};
// Set up the request
var post_req = http.request(post_options, function(res) {
res.on('data', function(data){
});
res.on('end', function(){
callback();
});
});
post_req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
post_req.write(JSON.stringify({image : data}));
post_req.end();
};
var currentImage = 0;
var availableImages = [];
var numberSent = 0;
var numberReceived = 0;
fs.readdir(__dirname + '/img', function(err, files){
availableImages = files;
startTest();
});
function startTest(){
var sendInterval = setInterval(
function(){
numberSent++;
var thisImage = availableImages[currentImage];
currentImage = (currentImage + 1) % availableImages.length;
var toB64 = convert.encode(__dirname + '/img/' + thisImage);
//console.log("Succesfuly converted: " + thisImage);
request(toB64, function(){
numberReceived++;
var performance = 100 / (numberSent - numberReceived + 1);
console.log("Performance: " + performance + "%");
});
console.log(numberSent + " - " + numberReceived);
},
config.captureInterval);
};