-
+ 8338A018F49BEE220073E50372407C6A47E2CD77847AEC8C73734DD0DC7060E750A5DF4306B8D955C220D49560926987DAB99B35615F5E5C7721D818EC0FAC22
udp/echodemo/udp_echo_demo.adb
(0 . 0)(1 . 69)
26 ------------------------------------------------------------------------------
27 ------------------------------------------------------------------------------
28 -- This file is part of 'UDP Echo Demo', accompanies 'UDP' library. --
29 -- --
30 -- (C) 2018 Stanislav Datskovskiy ( www.loper-os.org ) --
31 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
32 -- --
33 -- You do not have, nor can you ever acquire the right to use, copy or --
34 -- distribute this software ; Should you use this software for any purpose, --
35 -- or copy and distribute it to anyone or in any manner, you are breaking --
36 -- the laws of whatever soi-disant jurisdiction, and you promise to --
37 -- continue doing so for the indefinite future. In any case, please --
38 -- always : read and understand any software ; verify any PGP signatures --
39 -- that you use - for any purpose. --
40 -- --
41 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
42 ------------------------------------------------------------------------------
43 ------------------------------------------------------------------------------
44
45 with Ada.Text_IO; use Ada.Text_IO;
46
47 with UDP;
48
49
50 procedure UDP_Echo_Demo is
51
52 Socket : UDP.Socket;
53
54 -- Local_Endpoint : UDP.Endpoint
55 -- := (Address => UDP.IP_From_String("127.0.0.1"),
56 -- Port => 7000);
57
58 Local_Endpoint : UDP.Endpoint := (Address => UDP.INADDR_ANY,
59 Port => 7000);
60
61 Received_Payload : UDP.Payload;
62 Received_Origin : UDP.Endpoint;
63 Received_Valid : Boolean;
64
65 begin
66 Put_Line("Opening socket on local endpoint " &
67 UDP.IP_To_String(Local_Endpoint.Address) &
68 " :" & UDP.IP_Port'Image(Local_Endpoint.Port) & "...");
69
70 UDP.Open_Socket(Socket, Local_Endpoint);
71
72 Put_Line("Waiting for payload...");
73
74 UDP.Receive(Socket, Received_Origin, Received_Payload, Received_Valid);
75
76 Put_Line("Received payload from " &
77 UDP.IP_To_String(Received_Origin.Address) &
78 " :" & UDP.IP_Port'Image(Received_Origin.Port) & "...");
79
80 if Received_Valid then
81
82 Put_Line("Sending received payload back to originator...");
83
84 UDP.Transmit(Socket, Received_Origin, Received_Payload);
85
86 else
87
88 Put_Line("Received short payload, ignored.");
89
90 end if;
91
92 Put_Line("Done.");
93
94 end UDP_Echo_Demo;