Module: anynet.udp

Provides a UDP socket and client.

class UDPSocket
A connectionless UDP socket.

class UDPClient
UDP socket that is connected to a specific address.

async with bind(host: str = "", port: int = 0, *, broadcast: bool = False) -> UDPSocket
Creates a UDP socket and binds it to the given address. If host is empty, the local address of the default gateway is used. If port is 0, it is chosen by the operating system. If broadcast is True, the socket is allowed to send packets to the broadcast address.

async with connect(host: str, port: int) -> UDPClient
Creates a UDP socket and connects it to the given address, i.e. all datagrams are sent to this address and datagrams that come from a different address are discarded.

UDPSocket

async def send(data: bytes, addr: tuple[str, int]) -> None
Sends a datagram to the given address.

async def recv() -> (bytes, tuple[str, int])
Receives a single datagram. Blocks if no datagram is available.

async def close() -> None
Closes the socket.

def local_address() -> tuple[str, int]
Returns the local address of the socket.

UDPClient

async def send(data: bytes) -> None
Sends a single datagram to the server.

async def recv() -> bytes
Receives a single datagram. Blocks if no datagram is available.

async def close() -> None
Closes the socket.

def local_address() -> tuple[str, int]
Returns the local address of the client.

def remote_address() -> tuple[str, int]
Returns the address that the client is connected to.