Datagram API

Send and receive datagrams and query latency

Structs

Net

struct Net {
    handle: Int
}

Member Functions

new

fn Net::new(host: String) -> Net

Connects to the specified host and port

write

fn Net::write(self, enum_payload: Any)

Send a datagram (a game specific enum)

The datagram is unreliable, so you have to keep sending until an answer is returned. or you give up and move to another “phase” in the game state.

read

fn Net::read(self, emum_payload: Any) -> Bool

Receive a datagram (must be an enum)

The datagram is unreliable, so you need to send an answer even if same (or similar) request has been handled earlier.

Example

endpoint := Net::new("server.example.com:55000")

mut game_enum: GameSpecificEnum

while endpoint.read(&game_enum) {
match game_enum {
// handle the variants
}
}

latency

fn Net::latency(self) -> Int

Return the latency in milliseconds