Skip to content
CryoCryo home
Stdlibnet::address

socket_address

import std::net::address::socket_address; · source

Types

SocketAddress

type struct SocketAddress {
    ip:   IpAddress;
    port: u16;
}

An IP address paired with a port. This is what every socket constructor takes — TcpListener::bind, TcpStream::connect, UdpSocket::bind — and what local_address() hands back.

any_v4(port) is 0.0.0.0:port, binding on every IPv4 interface; localhost_v4(port) is 127.0.0.1:port; the _v6 pair are [::] and [::1]. parse reads an endpoint in the form Display writes: a.b.c.d:port, or an IPv6 address in brackets with the port after them, [::1]:8080 (RFC 3986). The port is a decimal number from 0 to 65535. It refuses with a ConversionError saying what was wrong when the text has neither form, its address does not parse, an IPv6 address is not in brackets, or the port is not such a number.

import std::net::address::socket_address::{ SocketAddress };

const address: SocketAddress = SocketAddress::any_v4(8080);

POD — copied by value, nothing to drop. Display prints a.b.c.d:port, or [v6]:port for an IPv6 address.

Properties

PropertyType
ipIpAddress
portu16

Constructors

static new(ip: IpAddress, port: u16) -> SocketAddress;

The endpoint ip:port.

static any_v4(port: u16) -> SocketAddress;

0.0.0.0:port: bind on every IPv4 interface.

static localhost_v4(port: u16) -> SocketAddress;

127.0.0.1:port: bind/connect on the loopback interface.

static any_v6(port: u16) -> SocketAddress;

[::]:port: bind on every IPv6 interface.

static localhost_v6(port: u16) -> SocketAddress;

[::1]:port: bind/connect on the IPv6 loopback interface.

static parse(source: Str) -> Result<SocketAddress, ConversionError>;

Parse an endpoint in the form Display writes: a.b.c.d:port, or an IPv6 address in brackets with the port after them, [::1]:8080 (RFC 3986). The port is a decimal number from 0 to 65535. Refused, with what was wrong, when the text has neither form, its address does not parse, an IPv6 address is not in brackets, or the port is not such a number.