-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path3-server.js
More file actions
50 lines (37 loc) · 970 Bytes
/
3-server.js
File metadata and controls
50 lines (37 loc) · 970 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
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const net = require('node:net');
const connection = (socket) => {
console.dir({
localAddress: socket.localAddress,
localPort: socket.localPort,
remoteAddress: socket.remoteAddress,
remoteFamily: socket.remoteFamily,
remotePort: socket.remotePort,
bufferSize: socket.bufferSize,
});
socket.write('💗');
socket.on('data', (data) => {
console.log('Event: 📨', data);
console.log('Data:', data.toString());
});
socket.on('drain', () => {
console.log('Event: 🤷');
});
socket.on('end', () => {
console.log('Event: 🏁');
console.dir({
bytesRead: socket.bytesRead,
bytesWritten: socket.bytesWritten,
});
});
socket.on('error', (err) => {
console.log('Event: 💩');
console.log(err);
});
socket.on('timeout', () => {
console.log('Event: ⌛');
});
};
const server = net.createServer();
server.on('connection', connection);
server.listen(2000);