raw
udp_genesis             1 ------------------------------------------------------------------------------
udp_genesis 2 ------------------------------------------------------------------------------
udp_genesis 3 -- This file is part of 'UDP Echo Demo', accompanies 'UDP' library. --
udp_genesis 4 -- --
udp_genesis 5 -- (C) 2018 Stanislav Datskovskiy ( www.loper-os.org ) --
udp_genesis 6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
udp_genesis 7 -- --
udp_genesis 8 -- You do not have, nor can you ever acquire the right to use, copy or --
udp_genesis 9 -- distribute this software ; Should you use this software for any purpose, --
udp_genesis 10 -- or copy and distribute it to anyone or in any manner, you are breaking --
udp_genesis 11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
udp_genesis 12 -- continue doing so for the indefinite future. In any case, please --
udp_genesis 13 -- always : read and understand any software ; verify any PGP signatures --
udp_genesis 14 -- that you use - for any purpose. --
udp_genesis 15 -- --
udp_genesis 16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
udp_genesis 17 ------------------------------------------------------------------------------
udp_genesis 18 ------------------------------------------------------------------------------
udp_genesis 19
udp_genesis 20 with Ada.Text_IO; use Ada.Text_IO;
udp_genesis 21
udp_genesis 22 with UDP;
udp_genesis 23
udp_genesis 24
udp_genesis 25 procedure UDP_Echo_Demo is
udp_genesis 26
udp_genesis 27 Socket : UDP.Socket;
udp_genesis 28
udp_genesis 29 -- Local_Endpoint : UDP.Endpoint
udp_genesis 30 -- := (Address => UDP.IP_From_String("127.0.0.1"),
udp_genesis 31 -- Port => 7000);
udp_genesis 32
udp_genesis 33 Local_Endpoint : UDP.Endpoint := (Address => UDP.INADDR_ANY,
udp_genesis 34 Port => 7000);
udp_genesis 35
udp_genesis 36 Received_Payload : UDP.Payload;
udp_genesis 37 Received_Origin : UDP.Endpoint;
udp_genesis 38 Received_Valid : Boolean;
udp_genesis 39
udp_genesis 40 begin
udp_genesis 41 Put_Line("Opening socket on local endpoint " &
udp_genesis 42 UDP.IP_To_String(Local_Endpoint.Address) &
udp_genesis 43 " :" & UDP.IP_Port'Image(Local_Endpoint.Port) & "...");
udp_genesis 44
udp_genesis 45 UDP.Open_Socket(Socket, Local_Endpoint);
udp_genesis 46
udp_genesis 47 Put_Line("Waiting for payload...");
udp_genesis 48
udp_genesis 49 UDP.Receive(Socket, Received_Origin, Received_Payload, Received_Valid);
udp_genesis 50
udp_genesis 51 Put_Line("Received payload from " &
udp_genesis 52 UDP.IP_To_String(Received_Origin.Address) &
udp_genesis 53 " :" & UDP.IP_Port'Image(Received_Origin.Port) & "...");
udp_genesis 54
udp_genesis 55 if Received_Valid then
udp_genesis 56
udp_genesis 57 Put_Line("Sending received payload back to originator...");
udp_genesis 58
udp_genesis 59 UDP.Transmit(Socket, Received_Origin, Received_Payload);
udp_genesis 60
udp_genesis 61 else
udp_genesis 62
udp_genesis 63 Put_Line("Received short payload, ignored.");
udp_genesis 64
udp_genesis 65 end if;
udp_genesis 66
udp_genesis 67 Put_Line("Done.");
udp_genesis 68
udp_genesis 69 end UDP_Echo_Demo;