This is an appendix to Understanding Unix/Linux Programming written for people interested in Ada programming on POSIX systems.

Programming with Datagrams: A License Server

Section 13.5, page 413-422

Section 13.5.2, page 415-419

The procedure Receive_Socket in GNAT.Sockets can be used to receive a datagram:

procedure Receive_Socket (Socket : in     Socket_Type;
                          Item   :    out Ada.Streams.Stream_Element_Array;
                          Last   :    out Ada.Streams.Stream_Element_Offset; 
                          From   :    out Sock_Addr_Type;
                          Flags  : in     Request_Flag_Type := No_Request_Flag);

The procedure Send_Socket in GNAT.Sockets can be used to send a datagram:

procedure Send_Socket (Socket : in     Socket_Type;
                       Item   : in     Ada.Streams.Stream_Element_Array;
                       Last   :    out Ada.Streams.Stream_Element_Offset;
                       To     : in     Sock_Addr_Type;
                       Flags  : in     Request_Flag_Type := No_Request_Flag)
Datagram receiver:
dgrecv.adb
Datagram sender:
dgsend.adb
Supporting functions:
eup-sockets.ads
eup-sockets.adb
eup-text_io.ads
eup-text_io.adb

Compile and test

% make dgrecv dgsend
[...]
% ./dgrecv 4444 &
[1] 10554
% ./dgsend localhost 4444 "testing 123"
dgrecv: got a message: testing 123
  from: 127.0.0.1:3611
%

Section 13.5.3, page 420-421

Receive_Socket

How much can you trust the data you receive from Receive_Socket?

Section 13.5.4, page 421-422

This modified version of dgrecv sends a reply whenever it receives a datagram: dgrecv2.adb

Section 13.5.6, page 423-427

-- 

The next chapter isn't ready yet.

Collected examples:
posix-in-ada.zip
Based on:
Understanding Unix/Linux Programming, Bruce Molay, ISBN 0-13-008396-8.
Main page:
http://edb.jacob-sparre.dk/Posix_in_Ada/
Written by:
Jacob Sparre Andersen.
Latest update:
12th of May, 2008