Skip to content
FutureBlitz

    Install

    Import std.net.game.host

    std.net.game.host

    std.net.game's hosts: GameHost, one end of any number of connections over a GameLink, a UdpSocket's or a test's, which it services at each Update, giving what happened as GameEvents: a peer that connected, a message that came, and a peer that disconnected.

    std/net/game/host.fb

    Types

    GameEventKind enum

    Public Enum GameEventKind

    What a GameEvent says happened.

    std/net/game/host.fb, line 40

    • CONNECT enum member #

      A peer connected.

    • RECEIVE enum member #

      A peer's message came.

    • DISCONNECT enum member #

      A peer disconnected, for its Reason.

    GameEvent struct

    Public Struct GameEvent Implements Printable

    Something that happened at a GameHost's Update: a peer connected, a message came from one on a channel, or a peer disconnected, and why.

    std/net/game/host.fb, line 51

    • Public ReadOnly Field Kind: GameEventKind field #

      What happened.

    • Public ReadOnly Field Peer: GamePeer field #

      The peer it happened to.

    • Public ReadOnly Field Channel: Int field #

      The channel a RECEIVE's message came on.

    • Public ReadOnly Field Bytes: UInt8[] field #

      A RECEIVE's message.

    • Public ReadOnly Field Reason: DisconnectReason field #

      Why a DISCONNECT's peer went.

    • Public Property Text: String property #

      A message's bytes as UTF-8.

    • Public Method ToString(): String method #

      As "CONNECT 127.0.0.1:5000", "RECEIVE 127.0.0.1:5000 on 0, 5 bytes", or "DISCONNECT 127.0.0.1:5000, TIMEOUT".

    GameHost class

    Public Class GameHost

    One end of connections over a GameLink. Connect asks another host for one, and a host takes those others ask for, up to its MaxPeers; each is a GamePeer, whose Send queues messages. Update takes what's come, sends what's due, and gives the events since the last; Service waits for some. A host whose link is its own, from Bind, closes it at Close.

    std/net/game/host.fb, line 95

    • @PanicsAtCaller Public New(link: GameLink, settings: GameSettings, seed: Int64? = Null) constructor #

      A host over link, with settings, whose salts and first sequences are random, or come from seed, so a test repeats. Panics for settings that don't make sense.

    • @PanicsAtCaller Public Static Method Bind(address: SocketAddress, settings: GameSettings): GameHost Throws NetError static method #

      A host over a UDP socket bound to address, as UdpSocket.Bind binds it, with settings.

    • Public Static Method Bind(address: SocketAddress): GameHost Throws NetError static method #

      A host over a UDP socket bound to address, with GameSettings().

    • Public Property LocalAddress: SocketAddress property #

      Where its link receives.

    • Public Property Peers: GamePeer[] property #

      The peers it's connected to, connecting to, or disconnecting from.

    • Public Property IsClosed: Bool property #

      Whether it's closed.

    • @PanicsAtCaller Public Method Connect(address: SocketAddress): GamePeer method #

      Asks the host at address for a connection, at the next Update and each ConnectRetry after, which gives a CONNECT event once it's accepted, or a DISCONNECT one when it's refused or the Timeout passes. A peer it has at address already is the one it gives. MaxPeers limits only the peers that connect to it. Panics once it's closed.

    • @PanicsAtCaller Public Method Broadcast(channel: Int, bytes: UInt8[]) method #

      Sends bytes on channel to every peer that's connected. Panics, peers or not, for a channel the host doesn't have, or a message past its MaxMessageSize, as a peer's Send does.

    • Public Method Update(now: Instant): GameEvent[] Throws NetError method #

      Takes what's come, then sends what's due, all as of now, and gives the events since the last Update. A closed host gives none. Throws a NetError only when its link fails for good.

    • Public Method Update(): GameEvent[] Throws NetError method #

      Update as of the clock's now.

    • Public Method Service(timeout: Duration): GameEvent[] Throws NetError method #

      Updates until there are events, waiting for what comes, up to timeout, and gives them, or none once timeout passes. A timeout too long for the clock waits as long as it takes.

    • Public Async Method ServiceAsync(timeout: Duration): GameEvent[] Throws NetError method #

      Service's Async twin, which waits on the main thread.

    • Public Method Close() method #

      Tells each peer it's connected to that it's going, without waiting for acks, and closes its link, giving no more events.

    Report an issue with this page or with FutureBlitz on GitHub.