-
Notifications
You must be signed in to change notification settings - Fork 0
/
dualreq.js
62 lines (48 loc) · 945 Bytes
/
dualreq.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
var http = require('http');
http.createServer(function (req, resp) {
var options1 = {
host: 'localhost',
port: 8001,
path: '/',
method: 'GET'
};
var options2 = {
host: 'localhost',
port: 8002,
path: '/',
method: 'GET'
};
var counter = 0;
var data1 = "";
var req = http.request(options1, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
data1 += chunk;
//resp.write(chunk);
});
res.on('end', function(){
counter++;
if(counter == 2)
{
resp.end(data1 + data2);
}
});
});
req.end();
var data2 = "";
var req2 = http.request(options2, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
data2 += chunk;
//resp.write(chunk);
});
res.on('end', function(){
counter++;
if(counter == 2)
{
resp.end(data1 + data2);
}
});
});
req2.end();
}).listen(1337, '127.0.0.1');