close
Skip to main content

@sys/net@0.0.152
Built and signed on GitHub Actions

Works with
This package works with Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score100%
License
MIT
Downloads4/wk
Published2 weeks ago (0.0.152)

Transport-layer utilities for ports, connections, and network readiness.

default

Namespaces

N

Type library (barrel file).

Type Aliases

T
t.NetConnectOptions = { hostname?: string; attempts?: number; delay?: t.Msecs; backoff?: number; }

Attempt to open a TCP connection to {port} (and optional {hostname}) with retry logic and exponential back-off.

  • attempts: number

    Maximum connection attempts before giving up (default 10).

  • backoff: number

    Factor applied to each subsequent delay (default 1.5).

  • delay: t.Msecs

    Delay (ms) before the first retry (default 100).

  • hostname: string

    Hostname or IP to connect to (default 127.0.0.1).

T
t.NetConnectResponse = { readonly socket?: Deno.TcpConn; readonly error?: t.StdError; }

Response from the Net.connect method.

  • error: t.StdError
    No documentation available
  • socket: Deno.TcpConn
    No documentation available
T
t.NetLib = { readonly Port: t.PortLib; readonly port: t.PortLib["get"]; waitFor(target: NetWaitTarget): Promise<void>; connect(
port: t.PortNumber,
options?: t.NetConnectOptions
): Promise<t.NetConnectResponse>; toUrl(
addr: Deno.NetAddr,
kind?: "http" | "ws"
): string; }

Tools for working with a network.

  • Port: t.PortLib

    Network port utilities.

  • connect(
    port: t.PortNumber,
    options?: t.NetConnectOptions
    ): Promise<t.NetConnectResponse>

    Attempt a TCP connection with retry and backoff.

  • port: t.PortLib["get"]

    Retrieve an available port (alias of Port.get).

  • toUrl(
    addr: Deno.NetAddr,
    kind?: "http" | "ws"
    ): string

    Format a network address as an http/https or ws/wss URL.

  • waitFor(target: NetWaitTarget): Promise<void>

    Wait until a network target is ready (e.g. an open WebSocket).

T
t.NetWaitTarget = WebSocket

Targets that can be waited on with Net.waitFor. Starts with WebSocket and can be extended over time.

T
t.PortLib = { get(
preference?: t.PortNumber,
options?: { throw?: boolean; }
): t.PortNumber; random(): t.PortNumber; inUse(port: t.PortNumber): boolean; }

Tools for working with network ports.

  • get(
    preference?: t.PortNumber,
    options?: { throw?: boolean; }
    ): t.PortNumber

    Retrieves a port number based on the provided preference or defaults to a pre-selected port.

  • inUse(port: t.PortNumber): boolean

    Determine if the given port number is currently in use.

  • random(): t.PortNumber

    Retrieve a random unused port number.

Variables

v
Net: t.NetLib

Tools for working with a network.

v
pkg: Pkg

Package metadata.

types

Type Aliases

T
NetConnectOptions = { hostname?: string; attempts?: number; delay?: t.Msecs; backoff?: number; }

Attempt to open a TCP connection to {port} (and optional {hostname}) with retry logic and exponential back-off.

  • attempts: number

    Maximum connection attempts before giving up (default 10).

  • backoff: number

    Factor applied to each subsequent delay (default 1.5).

  • delay: t.Msecs

    Delay (ms) before the first retry (default 100).

  • hostname: string

    Hostname or IP to connect to (default 127.0.0.1).

T
NetConnectResponse = { readonly socket?: Deno.TcpConn; readonly error?: t.StdError; }

Response from the Net.connect method.

  • error: t.StdError
    No documentation available
  • socket: Deno.TcpConn
    No documentation available
T
NetLib = { readonly Port: t.PortLib; readonly port: t.PortLib["get"]; waitFor(target: NetWaitTarget): Promise<void>; connect(
port: t.PortNumber,
options?: t.NetConnectOptions
): Promise<t.NetConnectResponse>; toUrl(
addr: Deno.NetAddr,
kind?: "http" | "ws"
): string; }

Tools for working with a network.

  • Port: t.PortLib

    Network port utilities.

  • connect(
    port: t.PortNumber,
    options?: t.NetConnectOptions
    ): Promise<t.NetConnectResponse>

    Attempt a TCP connection with retry and backoff.

  • port: t.PortLib["get"]

    Retrieve an available port (alias of Port.get).

  • toUrl(
    addr: Deno.NetAddr,
    kind?: "http" | "ws"
    ): string

    Format a network address as an http/https or ws/wss URL.

  • waitFor(target: NetWaitTarget): Promise<void>

    Wait until a network target is ready (e.g. an open WebSocket).

T
NetWaitTarget = WebSocket

Targets that can be waited on with Net.waitFor. Starts with WebSocket and can be extended over time.

T
PortLib = { get(
preference?: t.PortNumber,
options?: { throw?: boolean; }
): t.PortNumber; random(): t.PortNumber; inUse(port: t.PortNumber): boolean; }

Tools for working with network ports.

  • get(
    preference?: t.PortNumber,
    options?: { throw?: boolean; }
    ): t.PortNumber

    Retrieves a port number based on the provided preference or defaults to a pre-selected port.

  • inUse(port: t.PortNumber): boolean

    Determine if the given port number is currently in use.

  • random(): t.PortNumber

    Retrieve a random unused port number.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@sys/net

Import symbol

import * as net from "@sys/net";
or

Import directly with a jsr specifier

import * as net from "jsr:@sys/net";