-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (29 loc) · 1.2 KB
/
Copy pathindex.js
File metadata and controls
37 lines (29 loc) · 1.2 KB
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
const net = require("net");
const PORT = 6969;
const server = net.createServer();
server.on("connection", function(sock) {
console.log("CONNECTED: " + sock.remoteAddress + ":" + sock.remotePort);
sock.setEncoding("utf8");
sock.write("This is The GNU Hurd. Welcome.\n\n> ");
sock.on("data", function(data) {
if (data.startsWith("exit")) {
sock.write("The GNU Hurd bids you farewell.");
console.log("DISCONNECTED: " + sock.remoteAddress + ":" + sock.remotePort)
sock.resetAndDestroy();
} else if (data.startsWith("help")) {
sock.write("The GNU Hurd is aware of the following commands:\n- exit : Exit The GNU Hurd\n- help : Ask The GNU Hurd to show the help info\n")
} else {
sock.write("The GNU Hurd is not familiar with this command:\n" + data);
}
sock.write("> ");
});
sock.on("end", function() {
console.log("DISCONNECTED: " + sock.remoteAddress + ":" + sock.remotePort)
});
sock.on("error", function(err) {
console.log("ERROR FOR " + sock.remoteAddress + ": " + err);
});
});
server.listen(PORT, () => {
console.log("Running on port " + PORT + ".");
});