Module: nintendo.nex.prudp

Provides a client and server for PRUDP. Originally, PRUDP implemented reliable and secure transmission on top of UDP, but the Nintendo Switch introduced a 'Lite' mode in which PRUDP is implemented on top of TCP or WebSockets instead.

class PRUDPClient
A PRUDP client.

async with connect(settings: Settings, host: str, port: int, vport: int = 1, type: int = 10, context: TLSContext = None, credentials: Credentials = None) -> PRUDPClient
Creates a PRUDP client and connects it to the given address. If context is provided, and the underlying transport supports this, the connections is secured with TLS. If credentials are provided they are sent to the server in the connection request. Blocks until the connection is ready and handshake has been performed.

async with serve(handler: Callable, settings: Settings, host: str = "", port: int = 0, vport: int = 1, type: int = 10, context: TLSContext = None, key: bytes = None) -> None
Creates a PRUDP server and binds it to the given address. If host is empty, the local address of the default interface is used. If port is 0, it is chosen by the operating system. handler must be an async function that accepts a PRUDPClient. The client is closed automatically when handler returns. If context is provided, and the underlying transport supports this, the server is secured with TLS. If key is provided it is used to decrypt the Kerberos tickets in connection requests. If key is None, the payload of connection requests is ignored an all client connections are accepted.

async with connect_transport(settings: Settings, host: str, port: int, context: TLSContext = None) -> PRUDPClientTransport
Creates a transport connection for the PRUDP protocol. This can be used to establish multiple PRUDP connections with a single socket.

async with serve_transport(settings: Settings, host: str = "", port: int = 0, TLSContext = None) -> PRUDPServerTransport
Creates a transport server for the PRUDP protocol. This can be used to host multiple PRUDP servers at a single port.

PRUDPClient

async def send(data: bytes, substream: int = 0) -> None
Sends a reliable data packet to the server through the given substream. Blocks if the send buffer is full. Packets are retransmitted automatically if no acknowledgement is received.

async def send_unreliable(data: bytes) -> None
Sends an unreliable data packet to the server. Blocks if the send buffer is full.

async def recv(substream: int = 0) -> bytes
Receives a single reliable data packet from the server from the given substream. Blocks if no reliable data is available.

async def recv_unreliable() -> bytes
Receives an unreliable data packet from the server. Blocks if no unreliable data is available.

async def close() -> None
Closes the connection forcefully by sending an unreliable disconnect packet three times.

async def disconnect() -> None
Closes the connection gracefully by sending a reliable disconnect packet.

def pid() -> int
Returns the user id of the connected client. Returns None if the client is connected without credentials.

def minor_version() -> int
Returns the PRUDP minor version that was negotiated during the handshake.

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.

def local_sid() -> int
Returns the local stream id (PRUDP port).

def remote_sid() -> int
Returns the remote stream id (PRUDP port).

PRUDPClientTransport

async with connect(port: int, type: int = 10, credentials: credentials: Credentials = None) -> PRUDPClient
Establishes a new PRUDP connection with the given PRUDP port.

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.

PRUDPServerTransport

async with serve(handler: Callable, port: int, type: int = 10, key: bytes = None) -> None
Creates a new PRUDP server at the given PRUDP port.