-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_server_test.js
More file actions
32 lines (20 loc) · 798 Bytes
/
new_server_test.js
File metadata and controls
32 lines (20 loc) · 798 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
const net = require('net');
const a = require('./sample_data.json');
const { encodeMessage } = require('./message-tools');
const sampleA = Buffer.from(JSON.stringify(a));
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
const server = net.createServer(async socket => {
for(let i = 0; i < 1000; i++) {
console.time(i);
const jsonString = JSON.parse(sampleA.toString());
const j = Array(6).fill(jsonString);
const data = {i, data: j};
const dataBuffer = Buffer.from(JSON.stringify(data), 'utf8');
const messageBuffer = encodeMessage(dataBuffer);
socket.write(messageBuffer);
await sleep(10);
console.timeEnd(i);
}
});
server.listen(5673, '127.0.0.1');
console.log('Server listening on port 5673');