-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.ts
40 lines (34 loc) · 770 Bytes
/
test.ts
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 { connect, createConnection } from "net";
main();
async function main() {
console.log("createconnection");
const socket = connect({
port: 80,
host: "google.com",
});
console.log("done");
socket.on("data", (data) => {
console.log(data.toString("utf-8"));
});
socket.on("error", (error) => {
console.log(error);
});
socket.on("end", () => {
console.log("end");
});
socket.write(`GET / HTTP/1.1
Host: www.google.com
User-Agent: curl/7.64.1
Accept: */*
`);
}
async function mainsocket() {
console.log("createconnection");
const socket = createConnection(3000, "0.0.0.0");
console.log("done");
console.log(socket);
for await (const chunck of socket) {
console.log("chunck");
console.log(chunck);
}
}