Using datagram sockets
Note: The example classes discussed in this section appear in the subdirectory datagram of the example directory.
Using datagram sockets implies a few differences from the preceding schemes. You create a NETWORK_DATAGRAM_SOCKET or a UNIX_DATAGRAM_SOCKET as before. You do not need to call listen, accept or connect. Once you have created your sockets using the make_client or make_server creation procedure, you can use the send and received routines, specifying the socket to which you want to send, or from which you want to receive.
The command send takes an argument of type DATAGRAM_PACKET , and the query received returns a result of this type. DATAGRAM_PACKET is an heir of class PACKET , itself an heir of ARRAY [ [[ref:libraries/base/reference/character_8_chart|CHARACTER]] ]. Class DATAGRAM_PACKET makes it possible, through the query number and the associated command set_number, to associate a packet number with each packet. This compensates for lack of guaranteed sequencing of datagram sockets: the sender can number packets through set_number, and the receiver can check that all packets have been received through number, asking the sender to re-emit missing objects.
The text of this example is similar to what appears below (in a more general setting involving event-driven computation) for the next example.