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.
-
Its bytes.
-
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.
-
Public Static Method Bind(address: SocketAddress, reuseAddress: Bool = False): UdpSocket Throws NetErrorstatic method #Binds a socket to
address, whose port 0 has the OS pick one, which LocalAddress tells. WithreuseAddress, 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 theaddress. -
Public Static Method Bind(host: String, port: UInt16, reuseAddress: Bool = False): UdpSocket Throws NetErrorstatic method #Binds a socket to
host's first address, as Dns.Resolve gives them, andport. -
Where it's bound, the port the OS picked included.
-
Whether Close closed it.
-
Sends
bytestotargetas 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. -
Send's Async twin, which waits on the main thread, with a copy of the
bytes. -
The next datagram, waiting up to
timeoutfor 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, TimeoutErrormethod #Receive's Async twin, which waits on the main thread.
-
Whether it may send to a broadcast address, which it can't until this says so.
-
Whether what it multicasts comes back to the sockets on this machine, as it does until this says otherwise.
-
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.
-
Multicasts from here on through the interface whose address is
on, rather than the one the OS picks. -
Receives what's multicast to
groupfrom here on, on the interface whose address ison, or the one the OS picks. -
Stops receiving what's multicast to
group. -
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.