<datagram> ( addrspec -- datagram )
Networking » Packet-oriented networking

Next:send ( bytes addrspec datagram -- )


Vocabulary
io.sockets

Inputs
addrspecan address specifier


Outputs
datagrama handle


Word description
Creates a datagram socket bound to a local address. Datagram socket objects responds to three words:
dispose - stops listening on the port and frees all associated resources
receive - waits for a packet
send - sends a packet


Notes
To accept UDP/IP packets from any host, use an address specifier where the host name is set to f:
f 1234 <inet4> <datagram>

To create a datagram socket bound to a randomly-assigned port, set the port number in the address specifier to 0, and then read the addr slot of the datagram instance to obtain the actual port number it is bound to:
f 0 <inet4> <datagram>

To accept UDP/IP packets from the loopback interface only, use an address specifier like the following:
"127.0.0.1" 1234 <inet4> <datagram>

Since resolve-host can return multiple address specifiers, your code must create a datagram socket for each one and coordinate packet sending accordingly.

Errors
Throws an error if the port is already in use, or if the OS forbids access.

Definition