TCP/TLS listener: Ping

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.

Edit on GitHub

Instantiate an instance of a TCP listener on localhost port 443.

const listener = Ende.listenTls({
  cert: Ende.readTextFileSync("./server.crt"),
  hostname: "127.0.0.1",
  key: Ende.readTextFileSync("./server.key"),
  port: 443,
  transport: "tcp"
});

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(Ende.stdout.writable);

We close the connection that was established.

  conn.close();
}

Run this example locally using the Ende CLI:

ende run -N -R https://docs.ende.sh/examples/scripts/tls_listener.ts

Additional resources