libretro.api.netpacket

Network packet exchange interface types for multiplayer.

Module Attributes

retro_netpacket_send_t

Send a network packet to one or all connected players.

retro_netpacket_receive_t

Deliver a packet received from another player to the core.

retro_netpacket_stop_t

Notify the core that the multiplayer session has ended.

retro_netpacket_poll_t

Allow the core to send packets between calls to retro_run().

retro_netpacket_poll_receive_t

Drain any pending incoming packets without waiting for the end of the frame.

retro_netpacket_connected_t

Notify the host's core that a new player has connected.

retro_netpacket_disconnected_t

Notify the host's core that a player has disconnected.

retro_netpacket_start_t

Notify the core that a multiplayer session has started.

BROADCAST

Client ID that targets all connected clients.

Classes

NetpacketFlags

Flags controlling network packet delivery.

retro_netpacket_callback

Corresponds to retro_netpacket_callback in libretro.h.

class retro_netpacket_callback[source]

Bases: Structure

Corresponds to retro_netpacket_callback in libretro.h.

A set of callbacks for network packet exchange.

>>> from libretro.api import retro_netpacket_callback
>>> cb = retro_netpacket_callback()
>>> cb.start is None
True
start

Called when a multiplayer session starts.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
receive

Called when a network packet is received.

stop

Called when the multiplayer session ends. Optional.

poll

Called each frame to poll for network events. Optional.

connected

Called when a new player connects. Host only. Optional.

disconnected

Called when a player disconnects. Host only. Optional.

protocol_version

Protocol version string for compatibility checks. Optional.

__deepcopy__(_)[source]

Return a deep copy of this object, including all strings. Intended for use with copy.deepcopy().

>>> import copy
>>> from libretro.api import retro_netpacket_callback
>>> copy.deepcopy(retro_netpacket_callback()).start is None
True
retro_netpacket_send_t

Send a network packet to one or all connected players.

Registered by the frontend and called by the core. A single packet may carry up to 64 KB of data.

Parameters:
  • flags – A bitmask of NetpacketFlags values that controls reliability, sequencing, and flushing.

  • buf – A c_void_ptr to the packet data, or None (combined with len of 0) to flush previously buffered packets.

  • len – Length of the data in buf, in bytes.

  • client_id – Recipient player’s client ID, or BROADCAST to send to every connected player.

Corresponds to retro_netpacket_send_t in libretro.h.

retro_netpacket_start_t

Notify the core that a multiplayer session has started.

Registered by the core and called by the frontend once the local player has joined the session. The core should retain send_fn (and optionally poll_receive_fn) for use until retro_netpacket_stop_t is called.

Parameters:
  • client_id – Local player’s client ID; 0 if the local player is the host.

  • send_fn – A retro_netpacket_send_t that the core uses to send packets.

  • poll_receive_fn – A retro_netpacket_poll_receive_t that the core uses for synchronous receives.

Corresponds to retro_netpacket_start_t in libretro.h.

retro_netpacket_receive_t

Deliver a packet received from another player to the core.

Registered by the core and called by the frontend when a packet arrives from another player.

Parameters:
  • buf – A c_void_ptr to the received packet data.

  • len – Length of the packet in buf, in bytes.

  • client_id – Client ID of the player that sent the packet.

Corresponds to retro_netpacket_receive_t in libretro.h.

retro_netpacket_stop_t

Notify the core that the multiplayer session has ended.

Registered by the core and called by the frontend. After this call returns, the function pointers passed to retro_netpacket_start_t are no longer valid.

Corresponds to retro_netpacket_stop_t in libretro.h.

retro_netpacket_poll_t

Allow the core to send packets between calls to retro_run().

Registered by the core and called by the frontend once per frame to update the multiplayer session.

Corresponds to retro_netpacket_poll_t in libretro.h.

retro_netpacket_poll_receive_t

Drain any pending incoming packets without waiting for the end of the frame.

Registered by the frontend and called by the core to receive packets immediately rather than waiting for the next frame.

Corresponds to retro_netpacket_poll_receive_t in libretro.h.

retro_netpacket_connected_t

Notify the host’s core that a new player has connected.

Registered by the core and called by the frontend on the host side only. The core may reject the new player by returning False.

Parameters:

client_id – Client ID of the newly-connected player.

Returns:

True to accept the connection, False to drop the player.

Corresponds to retro_netpacket_connected_t in libretro.h.

retro_netpacket_disconnected_t

Notify the host’s core that a player has disconnected.

Registered by the core and called by the frontend on the host side only.

Parameters:

client_id – Client ID of the player that disconnected.

Corresponds to retro_netpacket_disconnected_t in libretro.h.

class NetpacketFlags[source]

Bases: IntFlag

Flags controlling network packet delivery.

>>> from libretro.api import NetpacketFlags
>>> NetpacketFlags.RELIABLE
<NetpacketFlags.RELIABLE: 1>
UNRELIABLE = 0
RELIABLE = 1
UNSEQUENCED = 2
FLUSH_HINT = 4
__new__(value)
other in self

Returns True if self has at least the same flags set as other.

iter(self)

Returns flags in definition order.

len(self)

Return the number of members (no aliases)

classmethod self[name]

Return the member matching name.

__init__()
BROADCAST = 65535

Client ID that targets all connected clients.