Skip to main content

A Deno Implementation of `connect()`, the TCP Socket API proposed within WinterCG, and implemented in Cloudflare Workers.

Works with
This package works with Deno
JSR Score
3 weeks ago


A Deno Implementation of the Cloudflare Socket API

Deno already has great support for TCP, but since Cloudflare proposed a WinterCG spec, this provides the same interface for Deno so we could migrate easier later on.

Inspired by, but with Deno's runtime APIs.


import { connect } from "";

export default {
  async fetch(request) {
    const gopherAddr = { hostname: "", port: 70 };
    const url = new URL(req.url);

    try {
      const socket = connect(gopherAddr);

      const writer = socket.writable.getWriter()
      const encoder = new TextEncoder();
      const encoded = encoder.encode(url.pathname + "\r\n");
      await writer.write(encoded);

      return new Response(socket.readable, { headers: { "Content-Type": "text/plain" } });
    } catch (error) {
      return new Response("Socket connection failed: " + error, { status: 500 });

The module can also be run as a simple CLI to send a message to a TCP server, similar to the example above, but send response to stdout.

For example:

$ deno run --allow-net mod.js /
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @sntran/socket

Import symbol

import * as mod from "@sntran/socket";