Skip to main content

TCP Echo Server

An echo server is a simple network application that listens for incoming connections and requests, and then repeats back any data it receives from clients.

To test this example, try sending data to it with Netcat (Linux/MacOS only). For example, in your terminal run: echo "Hello, Deno!" | nc localhost 8080`

Edit on Github
Create a TCP listener that listens on port 8080. Log that it is listening.
const listener = Deno.listen({ port: 8080 });
console.log("listening on 0.0.0.0:8080");
Wait for incoming connections, When a client connects to the server, read data from the client and write it back to the client.
for await (const conn of listener) {
  conn.readable.pipeTo(conn.writable);
}

Run this example locally using the Deno CLI:

deno run --allow-net echo_server.ts