Datagram

Datagrams provide a low-overhead, non-reliable data transmission mechanism.

Datagrams are not 'connected' in the same manner as a TCP socket; you don't need to listen() or accept() to receive a datagram, and data may arrive from multiple sources. A datagram socket may, however, still use the connect() method like a TCP socket. When connected, the read() and write() methods will be restricted to a single address rather than being open instead. That is, applying connect() will make the address argument to both read() and write() irrelevant. Without connect(), method write() must be supplied with an address and method read() should be supplied with one to identify where data originated.

Note that when used as a listener, you must first bind the socket to a local adapter. This can be achieved by binding the socket to an InternetAddress constructed with a port only (ADDR_ANY), thus requesting the OS to assign the address of a local network adapter

Constructors

this
this()

Create a read/write datagram socket

Members

Functions

read
size_t read(void[] src)

Populate the provided array from the socket. This will stall until some data is available, or a timeout occurs. We assume the datagram has been connected.

read
size_t read(void[] dst, Address from)

Read bytes from an available datagram into the given array. When provided, the 'from' address will be populated with the origin of the incoming data. Note that we employ the timeout mechanics exposed via our Socket superclass.

write
size_t write(const(void)[] src)

Write the provided content to the socket. This will stall until the socket responds in some manner. We assume the datagram has been connected.

write
size_t write(const(void)[] src, Address to)

Write an array to the specified address. If address 'to' is null, it is assumed the socket has been connected instead.

Inherited Members

From Socket

socket
alias socket = native
Undocumented in source.
setTimeout
deprecated void setTimeout(double t)

see super.timeout(int)

hadTimeout
deprecated bool hadTimeout()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()

Return the name of this device

fileHandle
Handle fileHandle [@property getter]

Models a handle-oriented device.

native
Berkeley* native [@property getter]

Return the socket wrapper

bufferSize
size_t bufferSize [@property getter]

Return a preferred size for buffering conduit I/O

connect
Socket connect(const(char)[] address, uint port)

Connect to the provided endpoint

connect
Socket connect(Address addr)

Connect to the provided endpoint

bind
Socket bind(Address address)

Bind this socket. This is typically used to configure a listening socket (such as a server or multicast socket). The address given should describe a local adapter, or specify the port alone (ADDR_ANY) to have the OS assign a local adapter address.

shutdown
Socket shutdown()

Inform other end of a connected socket that we're no longer available. In general, this should be invoked before close()

detach
void detach()

Release this Socket

read
size_t read(void[] dst)

Read content from the socket. Note that the operation may timeout if method setTimeout() has been invoked with a non-zero value.

write
size_t write(const(void)[] src)
copy
OutputStream copy(InputStream src, size_t max)

Transfer the content of another conduit to this one. Returns the dst OutputStream, or throws IOException on failure.

wait
bool wait(bool reading)

Manage socket IO under a timeout

error
void error()

Throw an IOException noting the last error

asyncCopy
Socket asyncCopy(Handle file)

Meta