class UdpSocket
pub class UdpSocket :: [Closeable]
Conforms to Closeable.
A UDP socket: datagrams sent to an address, and received with their sender's.
Methods
pub static fn bind(addr: SocketAddr): UdpSocket throws IoError
Returns a socket bound to addr; port 0 asks the system for a free one, which localAddr
reports.
Errors
Throws IoError with the address when the socket cannot be created or bound.
pub mut fn sendTo(from: Slice<uint8>, addr: SocketAddr): int throws [IoError, Cancelled]
Sends from as one datagram to addr, waiting until the system takes it, and returns how
many bytes went — all of them, since a datagram goes whole or not at all.
Errors
Throws IoError — Closed after close(), else the system's failure with the address —,
and Cancelled when the waiting task is cancelled.
pub mut fn recvFrom(into: Slice<uint8>): (int, SocketAddr) throws [IoError, Cancelled]
Receives the next datagram, waiting until one comes, and returns how many of its bytes went
into into — the rest of a longer one is lost — and who sent it.
Errors
Throws IoError — Closed after close() —, and Cancelled when the waiting task is
cancelled.
pub fn localAddr(): SocketAddr throws IoError
Returns the address it is bound to — with the port the system chose, where bind asked
for 0.
Errors
Throws IoError: Closed after close(), else the system's failure.
pub fn close(): void throws IoError
Closes the socket; a task that waits in one of its calls throws Closed. A second close
does nothing.
Errors
Throws IoError when the system fails to close it.