-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
25 lines (21 loc) · 818 Bytes
/
Copy pathserver.js
File metadata and controls
25 lines (21 loc) · 818 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
import { createServer } from 'node:net';
// System Ports (0-1023), User Ports (1024-49151),
// and the Dynamic and/or Private Ports (49152-65535)
const PORT = 4200;
// 127.0.0.1 ip address for loopback interface,
// this interface sends all responses back to this machine only;
// 'localhost' alias for this ip address
const IP_ADDRESS = '127.0.0.1';
// but we can specify an ip address,
// that was given to our machine by the router/switch/wifi-router,
// then any machine (that connected to this router)
// in this network can send request to our machine
// using that ip address and port number
const server = createServer(async socket => {
for await (const chunk of socket) {
console.log(chunk.toString());
}
});
server.listen(PORT, IP_ADDRESS, () => {
console.log(`server runs:`, server.address());
});