IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

SocketAddrV4

struct SocketAddrV4

Represents an IPv4 socket address: an IPv4 address and a port.

Implemented traits​

AnyType, Copyable, Deinitable, Equatable, Hashable, ImplicitlyCopyable, Movable, Writable

Methods​

__init__​

def __init__(out self, ip: Ipv4Addr, port: UInt16)

Constructs a socket address from an IPv4 address and a port.

Args:

  • ​ip (Ipv4Addr): The IPv4 address.
  • ​port (UInt16): The port number in host byte order.

ip​

def ip(self) -> Ipv4Addr

Returns the IPv4 address.

Returns:

Ipv4Addr: The IPv4 address.

port​

def port(self) -> UInt16

Returns the port number.

Returns:

UInt16: The port number in host byte order.

write_to​

def write_to(self, mut writer: T)

Writes the socket address as address:port, such as 127.0.0.1:8080.

Args:

  • ​writer (T): The writer to write to.