-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
30 lines (27 loc) · 742 Bytes
/
main.ts
File metadata and controls
30 lines (27 loc) · 742 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
import net from "node:net";
import fs from "node:fs/promises";
const server = net.createServer(async (socket) => {
socket.write("Now you are connected to P2P Main Server !");
socket.on("data", (data) => {
console.log(data.toString());
});
socket.on("end", () => {
socket.write("file-uploaded");
});
let ip = socket.remoteAddress;
socket.on("close", (err) => {
if (err) {
console.log("Client Disconnected with error !!");
console.log(`Client IP: ${ip}`);
} else {
console.log("Client Disconnected !!");
console.log(`Client IP: ${ip}`);
}
});
});
server.on("error", (err) => {
console.log(err.message);
});
server.listen(3000, "0.0.0.0", () => {
console.log("Server Up!");
});