udp_genesis 1
udp_genesis 2
udp_genesis 3
udp_genesis 4
udp_genesis 5
udp_genesis 6
udp_genesis 7
udp_genesis 8
udp_genesis 9
udp_genesis 10
udp_genesis 11
udp_genesis 12
udp_genesis 13
udp_genesis 14
udp_genesis 15
udp_genesis 16
udp_genesis 17
udp_genesis 18
udp_genesis 19
udp_genesis 20 with Ada.Text_IO; use Ada.Text_IO;
udp_genesis 21 with Interfaces; use Interfaces;
udp_genesis 22
udp_genesis 23 with UDP; use UDP;
udp_genesis 24
udp_genesis 25
udp_genesis 26 procedure UDP_Tx_Demo is
udp_genesis 27
udp_genesis 28 Socket : UDP.Socket;
udp_genesis 29
udp_genesis 30
udp_genesis 31 Local_Endpoint : UDP.Endpoint := (Address => UDP.INADDR_ANY,
udp_genesis 32 Port => 5000);
udp_genesis 33
udp_genesis 34 Remote_Endpoint : UDP.Endpoint
udp_genesis 35 := (Address => UDP.IP_From_String("0.0.0.0"),
udp_genesis 36 Port => 7000);
udp_genesis 37
udp_genesis 38
udp_genesis 39
udp_genesis 40
udp_genesis 41
udp_genesis 42
udp_genesis 43
udp_genesis 44 Sent_Payload : UDP.Payload;
udp_genesis 45 Received_Payload : UDP.Payload;
udp_genesis 46 Received_Origin : UDP.Endpoint;
udp_genesis 47 Received_Valid : Boolean;
udp_genesis 48
udp_genesis 49 begin
udp_genesis 50 Put_Line("Generating " &
udp_genesis 51 UDP.Payload_Size'Image(Sent_Payload'Length) & "-byte turd...");
udp_genesis 52
udp_genesis 53 for I in Sent_Payload'Range loop
udp_genesis 54 Sent_Payload(I) := Unsigned_8(I mod 256);
udp_genesis 55 end loop;
udp_genesis 56
udp_genesis 57 Put_Line("Opening socket on local endpoint " &
udp_genesis 58 UDP.IP_To_String(Local_Endpoint.Address) &
udp_genesis 59 " :" & UDP.IP_Port'Image(Local_Endpoint.Port) & "...");
udp_genesis 60
udp_genesis 61 UDP.Open_Socket(Socket, Local_Endpoint);
udp_genesis 62
udp_genesis 63 Put_Line("Sending turd to " &
udp_genesis 64 UDP.IP_To_String(Remote_Endpoint.Address) &
udp_genesis 65 " :" & UDP.IP_Port'Image(Remote_Endpoint.Port) & "...");
udp_genesis 66
udp_genesis 67 UDP.Transmit(Socket, Remote_Endpoint, Sent_Payload);
udp_genesis 68
udp_genesis 69 Put_Line("Waiting for echo...");
udp_genesis 70
udp_genesis 71 UDP.Receive(Socket, Received_Origin, Received_Payload, Received_Valid);
udp_genesis 72
udp_genesis 73 Put_Line("Received payload from " &
udp_genesis 74 UDP.IP_To_String(Received_Origin.Address) &
udp_genesis 75 " :" & UDP.IP_Port'Image(Received_Origin.Port) & "...");
udp_genesis 76
udp_genesis 77 if Received_Valid then
udp_genesis 78
udp_genesis 79 if Received_Payload = Sent_Payload then
udp_genesis 80 Put_Line("Echo came back equal to the send turd!");
udp_genesis 81 else
udp_genesis 82 Put_Line("Echo came back mutilated!");
udp_genesis 83 end if;
udp_genesis 84
udp_genesis 85 else
udp_genesis 86
udp_genesis 87 Put_Line("Received short payload, ignored.");
udp_genesis 88
udp_genesis 89 end if;
udp_genesis 90
udp_genesis 91 Put_Line("Done.");
udp_genesis 92
udp_genesis 93 end UDP_Tx_Demo;