TCP Connector: Ping


An example of connecting to a TCP server on localhost and writing a 'ping' message to the server.

Instantiate an instance of text encoder to write to the TCP stream.
const encoder = new TextEncoder();
Establish a connection to our TCP server that is currently being run on localhost port 8080.
const conn = await Deno.connect({
  hostname: "",
  port: 8080,
  transport: "tcp",
Encode the 'ping' message and write to the TCP connection for the server to receive.
await conn.write(encoder.encode("ping"));

Run this example locally using the Deno CLI:

deno run --allow-net