API Reference¶
This is the API reference generated from the source code.
A better API for asynchronous UDP.
- class aioudp.Connection(send_func: Callable[[bytes], None], recv_func: Callable[[], Awaitable[None | bytes]], is_closing: Callable[[], bool], get_local_addr: Callable[[], Tuple[str, int]], get_remote_addr: Callable[[], None | Tuple[str, int]], closed: bool = False)¶
Represents a server-client connection. Do not instantiate manually.
- property local_address: Tuple[str, int]¶
Returns the local address of the connection. This is your IP.
See also
- Returns:
AddrType
- Return type:
This is a tuple containing the hostname and port
- async recv() bytes¶
Receives a message from the connection.
- Returns:
bytes
- Return type:
The received bytes.
- Raises:
exceptions.ConnectionClosedError – The connection is closed:
- property remote_address: None | Tuple[str, int]¶
Returns the remote address of the connection. This is their IP.
See also
- Returns:
AddrType
- Return type:
This is a tuple containing the hostname and port
- aioudp.connect(host: str, port: int) AsyncIterator[Connection]¶
Connect to a UDP server.
See Also:¶
Args:¶
host (str): The server’s host name/address. port (int): The server’s port number.
Returns:¶
An asynchronous iterator yielding a connection to the UDP server.
- aioudp.serve(host: str, port: int, handler: Callable[[Connection], Awaitable[None]]) AsyncIterator[None]¶
Run a UDP server.
See the docs for an example UDP echo server
See Also:¶
Args:¶
host (str): The host name/address to run the server on port (int): The port number to run the server on handler (Callable[[connection.Connection], Awaitable[None]]):
An asynchronous function to handle a request It should accept an instance of
connection.Connectionand doesn’t need to return anything.
Exceptions¶
Exceptions this library might raise.
- exception aioudp.exceptions.AioUDPError¶
Base exception for this library.
All exceptions this library will raise will subclass this
- exception aioudp.exceptions.ConnectionClosedError¶
When a connection is closed and you tried to send/recieve a message.