Fix 0 and 1
This commit is contained in:
parent
68178cee60
commit
95cee18537
4
0.ts
4
0.ts
|
@ -5,6 +5,10 @@ const PORT = 5588;
|
||||||
console.log(`Listening on port ${PORT}`);
|
console.log(`Listening on port ${PORT}`);
|
||||||
|
|
||||||
for await (const conn of Deno.listen({ port: PORT })) {
|
for await (const conn of Deno.listen({ port: PORT })) {
|
||||||
|
echo(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function echo(conn: Deno.Conn) {
|
||||||
await copy(conn, conn);
|
await copy(conn, conn);
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
|
|
8
1.ts
8
1.ts
|
@ -6,6 +6,10 @@ const tEnc = new TextEncoder();
|
||||||
|
|
||||||
console.log(`Listening on port ${PORT}`);
|
console.log(`Listening on port ${PORT}`);
|
||||||
for await (const conn of Deno.listen({ port: PORT })) {
|
for await (const conn of Deno.listen({ port: PORT })) {
|
||||||
|
processRequestStream(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function processRequestStream(conn: Deno.Conn) {
|
||||||
console.log("Connection established:", conn.remoteAddr);
|
console.log("Connection established:", conn.remoteAddr);
|
||||||
try {
|
try {
|
||||||
for await (const request of requests(conn)) {
|
for await (const request of requests(conn)) {
|
||||||
|
@ -25,10 +29,10 @@ for await (const conn of Deno.listen({ port: PORT })) {
|
||||||
prime: isPrime(request.number),
|
prime: isPrime(request.number),
|
||||||
};
|
};
|
||||||
console.debug("Response:", response);
|
console.debug("Response:", response);
|
||||||
await conn.write(tEnc.encode(JSON.stringify(response) + "\n"));
|
conn.write(tEnc.encode(JSON.stringify(response) + "\n"));
|
||||||
} else {
|
} else {
|
||||||
console.debug("Request malformed");
|
console.debug("Request malformed");
|
||||||
await conn.write(tEnc.encode("Malformed!\n"));
|
conn.write(tEnc.encode("Malformed!\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in a new issue