-
+ 40398049EB151A9D306259D68A3865847C6591020AD12DA0D9E374DF9B5B8B7C2812576ED9298E83B115AC6636FE402B398C0810287E0CBF7904A05D2632F918udp/txdemo/udp_tx_demo.adb(0 . 0)(1 . 93)
800 ------------------------------------------------------------------------------
801 ------------------------------------------------------------------------------
802 -- This file is part of 'UDP Tx Demo', accompanies 'UDP' library. --
803 -- --
804 -- (C) 2018 Stanislav Datskovskiy ( www.loper-os.org ) --
805 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
806 -- --
807 -- You do not have, nor can you ever acquire the right to use, copy or --
808 -- distribute this software ; Should you use this software for any purpose, --
809 -- or copy and distribute it to anyone or in any manner, you are breaking --
810 -- the laws of whatever soi-disant jurisdiction, and you promise to --
811 -- continue doing so for the indefinite future. In any case, please --
812 -- always : read and understand any software ; verify any PGP signatures --
813 -- that you use - for any purpose. --
814 -- --
815 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
816 ------------------------------------------------------------------------------
817 ------------------------------------------------------------------------------
818
819 with Ada.Text_IO; use Ada.Text_IO;
820 with Interfaces; use Interfaces;
821
822 with UDP; use UDP;
823
824
825 procedure UDP_Tx_Demo is
826
827 Socket : UDP.Socket;
828
829
830 Local_Endpoint : UDP.Endpoint := (Address => UDP.INADDR_ANY,
831 Port => 5000);
832
833 Remote_Endpoint : UDP.Endpoint
834 := (Address => UDP.IP_From_String("0.0.0.0"),
835 Port => 7000);
836
837 ----- Dulap test, replace with your own -----
838 -- Remote_Endpoint : UDP.Endpoint
839 -- := (Address => UDP.IP_From_String("161.0.121.200"),
840 -- Port => 7000);
841 ----------------------------------------------
842
843 Sent_Payload : UDP.Payload;
844 Received_Payload : UDP.Payload;
845 Received_Origin : UDP.Endpoint;
846 Received_Valid : Boolean;
847
848 begin
849 Put_Line("Generating " &
850 UDP.Payload_Size'Image(Sent_Payload'Length) & "-byte turd...");
851
852 for I in Sent_Payload'Range loop
853 Sent_Payload(I) := Unsigned_8(I mod 256);
854 end loop;
855
856 Put_Line("Opening socket on local endpoint " &
857 UDP.IP_To_String(Local_Endpoint.Address) &
858 " :" & UDP.IP_Port'Image(Local_Endpoint.Port) & "...");
859
860 UDP.Open_Socket(Socket, Local_Endpoint);
861
862 Put_Line("Sending turd to " &
863 UDP.IP_To_String(Remote_Endpoint.Address) &
864 " :" & UDP.IP_Port'Image(Remote_Endpoint.Port) & "...");
865
866 UDP.Transmit(Socket, Remote_Endpoint, Sent_Payload);
867
868 Put_Line("Waiting for echo...");
869
870 UDP.Receive(Socket, Received_Origin, Received_Payload, Received_Valid);
871
872 Put_Line("Received payload from " &
873 UDP.IP_To_String(Received_Origin.Address) &
874 " :" & UDP.IP_Port'Image(Received_Origin.Port) & "...");
875
876 if Received_Valid then
877
878 if Received_Payload = Sent_Payload then
879 Put_Line("Echo came back equal to the send turd!");
880 else
881 Put_Line("Echo came back mutilated!");
882 end if;
883
884 else
885
886 Put_Line("Received short payload, ignored.");
887
888 end if;
889
890 Put_Line("Done.");
891
892 end UDP_Tx_Demo;