-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugClient.js
43 lines (37 loc) · 1.21 KB
/
debugClient.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
const net = require('net');
let testing = false;
const server = new net.Socket();
server.connect(2333, '192.168.1.1');
server.on('data', data => {
const dataLineSet = data.toString().split("\r\n");
dataLineSet.forEach(data => {
if (data === '') return;
const dataStr = data.replace(/\n/g, '').split(/[, ]/);
const command = dataStr[0];
const parameter = dataStr.slice(1);
console.log(`[RECV] ${dataStr}`);
switch(command) {
case 'WHO':
server.write(`TP dbg`);
break;
case 'ST':
if (testing) break;
testing = true;
let packageCount = 0;
let tick = setInterval(() => {
let msg = `DEBUG DPKG${packageCount}`;
//console.log(msg);
server.write(msg);
packageCount ++;
if (packageCount >= 1000) {
clearInterval(tick);
console.log(`[INFO] Finished debugging, the program will shut down now.`);
server.destroy();
}
},1);
break;
default:
console.log('[????] Unknown command.');
}
});
});