-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
46 lines (39 loc) · 1002 Bytes
/
example.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
const Loris = require('./index.js'),
{Server} = require('http.server');
let port = 1000 + Math.floor(Math.random() * 6800);
let s = new Server(port), l = null;
s.create((req, res) => {
process.stdout.write('*');
res.status(200).send(':)');
}).then((server) => {
console.log('started server on', port);
let open = 0;
const log = setInterval(() => {
console.log('\nconnections', open);
}, 1000);
server.on('connection', (socket) => {
process.stdout.write('.');
open += 1;
socket.once('close', () => {
open += -1;
});
});
server.on('clientError', (err) => {
console.log(err);
});
server.on('error', (err) => {
console.log(err);
});
setTimeout(() => {
console.log('stop');
l.stop();
s.close();
clearInterval(log);
}, 1000 * 10);
l = new Loris('http://localhost:' + port, 100000).attack();
console.log('attack');
return new Promise((resolve) => l.once('end', resolve));
}).then(() => {
console.log('attack ended');
process.exit(0);
}).catch(console.log);