Packet-oriented networking
Networking

Prev:Connection-oriented networking


A packet-oriented socket can be opened with this word:
<datagram> ( addrspec -- datagram )


Packets can be sent and received with a pair of words:
send ( bytes addrspec datagram -- )

receive ( datagram -- bytes addrspec )


Packet-oriented sockets are closed by calling dispose.

Address specifiers have the following interpretation with packet-oriented networking words:
local - Unix domain datagram sockets on Unix systems
inet4 - a TCP/IP connection to an IPv4 address and port number; no name lookup is performed
inet6 - a TCP/IP connection to an IPv6 address and port number; no name lookup is performed

The inet address specifier is not supported by the send word because a single host name can resolve to any number of IPv4 or IPv6 addresses, therefore there is no way to know which address should be used. Applications should call resolve-host then use some kind of strategy to pick the correct address (for example, by sending a packet to each one and waiting for a response, or always assuming IPv4).