Online Eiffel Documentation
EiffelStudio

Using datagram sockets

The example classes discussed in this section appear in the subdirectorydatagram of the example directory

Using datagram sockets implies a few differences from the preceding schemes. You create aNETWORK_DATAGRAM_SOCKET or a UNIX_DATAGRAM_SOCKET as before. You do not need to calllisten,accept orconnect. Once you have created your sockets using themake_client ormake_server creation procedure, you can use thesend andreceived routines, specifying the socket to which you want to send, or from which you want to receive.

The commandsend takes an argument of typeDATAGRAM_PACKET, and the queryreceived returns a result of this type.DATAGRAM_PACKET is an heir of classPACKET, itself an heir ofARRAY [CHARACTER]. ClassDATAGRAM_PACKET makes it possible, through the querynumber and the associated commandset_number, to associate a packet number with each packet. This compensates for lack of guaranteed sequencing of datagram sockets: the sender can number packets throughset_number, and the receiver can check that all packets have been received throughnumber, 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.