------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- This file is part of 'UDP Echo Demo', accompanies 'UDP' library. -- -- -- -- (C) 2018 Stanislav Datskovskiy ( www.loper-os.org ) -- -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html -- -- -- -- You do not have, nor can you ever acquire the right to use, copy or -- -- distribute this software ; Should you use this software for any purpose, -- -- or copy and distribute it to anyone or in any manner, you are breaking -- -- the laws of whatever soi-disant jurisdiction, and you promise to -- -- continue doing so for the indefinite future. In any case, please -- -- always : read and understand any software ; verify any PGP signatures -- -- that you use - for any purpose. -- -- -- -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Ada.Text_IO; use Ada.Text_IO; with UDP; procedure UDP_Echo_Demo is Socket : UDP.Socket; -- Local_Endpoint : UDP.Endpoint -- := (Address => UDP.IP_From_String("127.0.0.1"), -- Port => 7000); Local_Endpoint : UDP.Endpoint := (Address => UDP.INADDR_ANY, Port => 7000); Received_Payload : UDP.Payload; Received_Origin : UDP.Endpoint; Received_Valid : Boolean; begin Put_Line("Opening socket on local endpoint " & UDP.IP_To_String(Local_Endpoint.Address) & " :" & UDP.IP_Port'Image(Local_Endpoint.Port) & "..."); UDP.Open_Socket(Socket, Local_Endpoint); Put_Line("Waiting for payload..."); UDP.Receive(Socket, Received_Origin, Received_Payload, Received_Valid); Put_Line("Received payload from " & UDP.IP_To_String(Received_Origin.Address) & " :" & UDP.IP_Port'Image(Received_Origin.Port) & "..."); if Received_Valid then Put_Line("Sending received payload back to originator..."); UDP.Transmit(Socket, Received_Origin, Received_Payload); else Put_Line("Received short payload, ignored."); end if; UDP.Close_Socket(Socket); Put_Line("Done."); end UDP_Echo_Demo;