Skip to content

parseSocketAddress ​

parseSocketAddress parses an address and port, including bracketed IPv6 notation.

The function validates the complete input without opening a socket. Invalid text produces an absent optional value.

SignatureparseSocketAddress(value: string): SocketAddress?
tyrus
import { SocketAddress, parseSocketAddress } from "tyrus:net";

const address: SocketAddress? = parseSocketAddress("[2001:db8::10]:443");
if (address) {
    print(address.port); // 443
}

Error Handling ​

error

tyrus
import { parseSocketAddress } from "tyrus:net";

const address = parseSocketAddress("127.0.0.1:99999");
print(address ?? "missing"); // "missing"

Invalid ports and malformed addresses produce the absent optional result; this function does not throw NetError.