Skip to content
FutureBlitz

    Install

    Import std.net.udp

    std.net.udp

    std.net's UDP: UdpSocket, which sends and receives datagrams, each whole or not at all, in no promised order, blocking or Async, with broadcast and multicast for what's on the LAN.

    std/net/udp.fb

    Types

    Datagram struct

    Public Struct Datagram

    A datagram a UdpSocket received: its bytes, and where it came from.

    std/net/udp.fb, line 20

    • Public ReadOnly Field Bytes: UInt8[] field #

      Its bytes.

    • Public ReadOnly Field From: SocketAddress field #

      Where it came from.

    UdpSocket class

    Public Class UdpSocket

    A UDP socket, bound to an address, which sends datagrams to any address and receives them from any: each arrives whole or not at all, maybe more than once, in no promised order. It closes when it goes, or at Close.

    std/net/udp.fb, line 35

    • Public Static Method Bind(address: SocketAddress, reuseAddress: Bool = False): UdpSocket Throws NetError static method #

      Binds a socket to address, whose port 0 has the OS pick one, which LocalAddress tells. With reuseAddress, others can bind the same address too, each receiving what's broadcast or multicast to it, as LAN discovery's do. Throws a NetError when it can't, as when another socket has the address.

    • Public Static Method Bind(host: String, port: UInt16, reuseAddress: Bool = False): UdpSocket Throws NetError static method #

      Binds a socket to host's first address, as Dns.Resolve gives them, and port.

    • Public Property LocalAddress: SocketAddress property #

      Where it's bound, the port the OS picked included.

    • Public Property IsClosed: Bool property #

      Whether Close closed it.

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

      Sends bytes to target as one datagram, of up to 65507 bytes, or what the OS sends at once, as macOS's 9216 unless it's told otherwise, returning once the OS has it, which doesn't say it arrived. A broadcast address needs SetBroadcast(True) first.

    • Public Async Method SendAsync(bytes: UInt8[], target: SocketAddress) Throws NetError method #

      Send's Async twin, which waits on the main thread, with a copy of the bytes.

    • Public Method Receive(timeout: Duration? = Null): Datagram Throws NetError, TimeoutError method #

      The next datagram, waiting up to timeout for one, or as long as it takes for a Null one, and throwing a TimeoutError after.

    • Public Async Method ReceiveAsync(timeout: Duration? = Null): Datagram Throws NetError, TimeoutError method #

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

    • Public Method SetBroadcast(on: Bool) Throws NetError method #

      Whether it may send to a broadcast address, which it can't until this says so.

    • Public Method SetMulticastLoopback(on: Bool) Throws NetError method #

      Whether what it multicasts comes back to the sockets on this machine, as it does until this says otherwise.

    • @PanicsAtCaller Public Method SetMulticastTtl(hops: Int) Throws NetError method #

      How many routers what it multicasts goes through, from 1, which keeps it on the LAN, as it does until this says otherwise, to 255, or it panics.

    • Public Method SetMulticastInterface(on: IpAddress) Throws NetError method #

      Multicasts from here on through the interface whose address is on, rather than the one the OS picks.

    • Public Method JoinMulticast(group: IpAddress, on: IpAddress? = Null) Throws NetError method #

      Receives what's multicast to group from here on, on the interface whose address is on, or the one the OS picks.

    • Public Method LeaveMulticast(group: IpAddress, on: IpAddress? = Null) Throws NetError method #

      Stops receiving what's multicast to group.

    • Public Method Close() method #

      Closes it at once: what's waiting for it throws a NetError of CLOSED, and so does what uses it after. Going closes it too.

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