-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.ts
More file actions
40 lines (38 loc) · 1000 Bytes
/
client.ts
File metadata and controls
40 lines (38 loc) · 1000 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
import type { Socket } from "node:dgram";
import net from "node:net";
import fs from "node:fs/promises";
const client = net.createConnection(
{
port: 3000,
host: "127.1.1.1",
},
() => {
console.log({
clientRules: "For sending file to servesr type- @send=filename.extension",
});
},
);
client.on("data", (data) => {
if (data.toString() == "file-uploaded") {
console.log(data.toString());
console.log(`Type: node client.js to send another files.`);
process.exit(0);
}
console.log(data.toString());
});
client.on("connect", () => {
process.stdin.on("data", async (msg) => {
const [flag, path] = msg.toString().replaceAll("\n", "").split("=");
if (!path) {
console.error("path not provided!");
}
try {
const open = await fs.open(`./${path}`);
const readStream = open.createReadStream();
readStream.pipe(client);
} catch (error: any) {
console.log(error.message);
process.exit(1);
}
});
});