Cauldron2D.Beacon (Cauldron2D v0.1.3)

Copy Markdown View Source

How a server on the local network is found: the host says so every two seconds on a UDP port — port/0, the :beacon_port in the :cauldron_2d config, 2299 unless set — to the broadcast address and to this machine, and whoever listens (Cauldron2D.Beacon.Listener) hears it.

{:ok, beacon} = Cauldron2D.Beacon.start_link(game: :my_game, host: "arcade", http: "http://192.168.1.5:2280", node: :"my_game@arcade")

A call is one line, cauldron 1 <game> <host> <http url or -> <node or ->. A node is joined with its cookie, which the host shows and the caller types; it never goes over the air.

Summary

Functions

Returns a specification to start this module under a supervisor.

The line a host calls with.

A call heard, or :error for anything else.

The UDP port the calls go out on: config :cauldron_2d, beacon_port: n, else 2299.

Start calling; :game the game's name, :host the name to call as, :http the web URL or nil, :node the node name or nil, :port the UDP port (default port/0).

Types

call()

@type call() :: %{
  game: String.t(),
  host: String.t(),
  http: String.t() | nil,
  node: atom() | nil
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

line(game, host, http, node)

@spec line(atom() | String.t(), String.t(), String.t() | nil, atom() | nil) ::
  String.t()

The line a host calls with.

parse(text)

@spec parse(String.t()) :: {:ok, call()} | :error

A call heard, or :error for anything else.

port()

@spec port() :: pos_integer()

The UDP port the calls go out on: config :cauldron_2d, beacon_port: n, else 2299.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Start calling; :game the game's name, :host the name to call as, :http the web URL or nil, :node the node name or nil, :port the UDP port (default port/0).