Vocabularyio.socketsInputs and outputs| addrspec | an address specifier |
| datagram | a handle |
Word descriptionCreates 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 |
NotesTo 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 co-ordinate packet sending accordingly.
ErrorsThrows an error if the port is already in use, or if the OS forbids access.
Definition