with Ada.Text_IO; with GNAT.Sockets; with Ada.Strings.Unbounded; with Ada.Streams; with Ada.Unchecked_Conversion; procedure sockets is package to renames Ada.Text_IO; package s renames GNAT.Sockets; package su renames Ada.Strings.Unbounded; package as renames Ada.Streams; host : constant String := "www.wp.pl"; HTTP_PORT : constant s.PORT_TYPE := 80; task ping is entry start; entry stop; end ping; task body ping is query : su.Unbounded_String := su.To_Unbounded_String(""); host2 : su.Unbounded_String; Address : s.Sock_Addr_Type; Socket : s.Socket_Type; Channel : s.Stream_Access; cr : constant Character := Character'Val(13); lf : constant Character := Character'Val(10); new_line : constant String := (cr, lf); output : as.Stream_Element_Array (1 .. 16#1000#); last : as.Stream_Element_Offset; output2 : su.Unbounded_String; begin to.Put("Ala"); to.Put(new_line); to.Put("Kot"); accept start; Address.Addr := s.Addresses (s.Get_Host_By_Name (host), 1); Address.Port := HTTP_PORT; s.Create_Socket (Socket); s.Set_Socket_Option ( Socket, s.Socket_Level, (s.Reuse_Address, True)); delay 0.2; to.Put_Line("Lacze z hostem"); s.Connect_Socket(Socket, Address); Channel := s.Stream (Socket); to.Put_Line("Wysylam dane"); su.Append(query, "GET / HTTP/1.1" & new_line); su.Append(query, "Host: " & host & new_line); su.Append(query, "Connection: close" & new_line); su.Append(query, new_line); String'Write(Channel, su.To_String(query)); to.Put_Line("Odbieram dane"); loop su.Delete(output2, 1, su.Length(output2)); as.Read(Channel.All, output, last); exit when Integer(last) = 0; declare subtype Output_String is String (1 .. Integer(last)); function Convert is new Ada.Unchecked_Conversion( Source => as.Stream_Element_Array, Target => Output_String); begin to.Put_Line(Convert(output (1 .. last))); end; end loop; to.Put_Line("Zamykam gniazdo"); s.Close_Socket(Socket); accept stop; to.Put_Line("ping stopped"); end ping; begin to.Put_Line("Hello World!!!"); ping.start; ping.stop; end sockets;