-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
39 lines (28 loc) · 892 Bytes
/
client.js
File metadata and controls
39 lines (28 loc) · 892 Bytes
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
const net = require('net');
const PORT = 7000;
const client = net.createConnection({ port: PORT }, () => {
console.log('connected to server');
const request = Buffer.alloc(6, 0);
request.writeUInt16BE(0x10, 0);
request.writeUInt16BE(0x06, 2);
request.writeUInt16LE(0x90, 4);
client.write(request);
});
client.on('data', (data) => {
const type = data.readUInt16BE(0);
const packetLength = data.readUInt16BE(2);
const action = data.readUint16LE(4);
const response = data.slice(6, packetLength).toString();
console.log(response);
if (action == 0x91)
{
const request = Buffer.alloc(6, 0);
request.writeUInt16BE(0x10, 0);
request.writeUInt16BE(0x06, 2);
request.writeUInt16LE(0x92, 4);
client.write(request);
}
});
client.on('end', () => {
console.log('disconnected from server');
});