Skip to content
FutureBlitz

    Install

    Import std.net.game.link

    std.net.game.link

    What a GameHost sends its packets over, and receives them from.

    A UdpSocket is one, through GameHost.Bind, and so is any Class that implements GameLink, as a test's link that loses packets on purpose does.

    std/net/game/link.fb

    Types

    Public Interface GameLink

    What a GameHost's datagrams go over, as UDP's do: each one whole or not at all, maybe more than once, in no promised order.

    Examples

    // A link that loses every packet, as a test of what a host does then can have.
    Class Nowhere Implements GameLink
        Public Property LocalAddress: SocketAddress
            Get => SocketAddress(IpAddress.Loopback, 9)
        End Property
    
        Public Method Send(bytes: UInt8[], to: SocketAddress) Throws NetError
        End Method
    
        Public Method Receive(timeout: Duration): (UInt8[], SocketAddress)? Throws NetError => Null
    
        Public Method Close()
        End Method
    End Class
    
    Local host = GameHost(Nowhere(), GameSettings())
    Local peer = host.Connect(SocketAddress(IpAddress.Loopback, 7777))
    Expect(peer.State == PeerState.CONNECTING)
    host.Close()

    std/net/game/link.fb, line 39

    • ReadOnly Property LocalAddress: SocketAddress property #

      Where it receives, as the other side sends to it.

    • Method Send(bytes: UInt8[], to: SocketAddress) Throws NetError method #

      Sends bytes to to as one datagram.

    • Method Receive(timeout: Duration): (UInt8[], SocketAddress)? Throws NetError method #

      The next datagram that's come, and where from, waiting for timeout at most, or Null when none came by then. A timeout of 0 takes what's come without waiting.

    • Async Method ReceiveAsync(timeout: Duration): (UInt8[], SocketAddress)? Throws NetError method #

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

    • Method Close() method #

      Closes it, if it holds anything to close.

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