gale.net.discovery module

This file contains LAN discovery: a small UDP broadcast protocol a Client can use to find Servers running on the same local network, without the player having to type an IP address. Deliberately LAN-only (relies on IP broadcast, which routers do not forward) and kept to tiny request/response packets, so it is not useful as an amplification vector: a public, internet-facing dedicated server should simply not call Server.enable_lan_discovery.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.net.discovery.ServerInfo(name, address, player_count)[source]

Bases: NamedTuple

Information about a Server found through LAN discovery.

Parameters:
  • name (str)

  • address (Tuple[str, int])

  • player_count (int)

name: str

Alias for field number 0

address: Tuple[str, int]

Alias for field number 1

player_count: int

Alias for field number 2

gale.net.discovery.discover_lan_servers(discovery_port=9998, timeout=1.0)[source]

Broadcast a discovery request on the local network and collect every reply that comes back within timeout seconds.

Parameters:
  • discovery_port (int) – The UDP port Servers are listening for discovery requests on (see Server.enable_lan_discovery). The default value is DEFAULT_DISCOVERY_PORT.

  • timeout (float) – How long to wait for replies, in seconds. The default value is 1.0.

Returns:

The list of ServerInfo found, one per replying Server.

Return type:

List[ServerInfo]