deno.com

TCP/TLS listener: Ping

在 Github 上编辑

An example of a TCP listener using TLS on localhost that will log the message if written to and close the connection if connected to.

Instantiate an instance of a TCP listener on localhost port 443.
const listener = Deno.listenTls({
  hostname: "127.0.0.1",
  port: 443,
  transport: "tcp",
  cert: Deno.readTextFileSync("./server.crt"),
  key: Deno.readTextFileSync("./server.key"),
});
Await asynchronous connections that are established to our TCP listener.
for await (const conn of listener) {
Pipe the contents of the TCP stream into stdout
  await conn.readable.pipeTo(Deno.stdout.writable);
We close the connection that was established.
  conn.close();
}

使用 Deno CLI 在本地运行 此示例

deno run --allow-net --allow-read https://docs.denohub.com/examples/scripts/tls_listener.ts

Additional resources

你找到需要的内容了吗?

隐私政策