------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- This file is part of 'UDP Tx 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 Interfaces; use Interfaces; with UDP; use UDP; procedure UDP_Tx_Demo is Socket : UDP.Socket; Local_Endpoint : UDP.Endpoint := (Address => UDP.INADDR_ANY, Port => 5000); Remote_Endpoint : UDP.Endpoint := (Address => UDP.IP_From_String("0.0.0.0"), Port => 7000); ----- Dulap test, replace with your own ----- -- Remote_Endpoint : UDP.Endpoint -- := (Address => UDP.IP_From_String("161.0.121.200"), -- Port => 7000); ---------------------------------------------- Sent_Payload : UDP.Payload; Received_Payload : UDP.Payload; Received_Origin : UDP.Endpoint; Received_Valid : Boolean; begin Put_Line("Generating " & UDP.Payload_Size'Image(Sent_Payload'Length) & "-byte turd..."); for I in Sent_Payload'Range loop Sent_Payload(I) := Unsigned_8(I mod 256); end loop; 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("Sending turd to " & UDP.IP_To_String(Remote_Endpoint.Address) & " :" & UDP.IP_Port'Image(Remote_Endpoint.Port) & "..."); UDP.Transmit(Socket, Remote_Endpoint, Sent_Payload); Put_Line("Waiting for echo..."); 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 if Received_Payload = Sent_Payload then Put_Line("Echo came back equal to the send turd!"); else Put_Line("Echo came back mutilated!"); end if; else Put_Line("Received short payload, ignored."); end if; Put_Line("Done."); end UDP_Tx_Demo;