From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7db5fb0599fd4b76,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail From: "fabio de francesco" Newsgroups: comp.lang.ada Subject: TCP/IP Sockets with GNAT.Sockets Date: 1 May 2005 19:42:32 -0700 Organization: http://groups.google.com Message-ID: <1115001752.291144.218410@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: 80.181.52.213 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1115001756 23449 127.0.0.1 (2 May 2005 02:42:36 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 2 May 2005 02:42:36 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=80.181.52.213; posting-account=Lp02jQ0AAABMd3TAghNf0TM2YBZqD_JE Xref: g2news1.google.com comp.lang.ada:10862 Date: 2005-05-01T19:42:32-07:00 List-Id: Hello, Today is the first time I try to use sockets in Ada programs, even if I have some practical knowledge of programming with TCP/IP sockets in C. Because I didn't find any better tutorial on working with GNAT.Sockets I am relying on comments in file g-socket.ads from GCC/GNAT sources where there is not a complete and detailed coverage of the subject. (1) Do you know any better tutorial? Then I wrote two little programs in order to try the package. A server waits for connections and a client sends a string and receive an echo from the first one. The client can also shutdown the server by sending a predefined string. I hadn't too many problems with exchanging messages and everything works. The problem is that I was only able to use Streams for communicating between them and I can't understand at all how to use Receive_Socket() and Send_Socket() because they use "Stream_Element_Array" and "Stream_Element _Offset" in place of Strings. I know that by using Streams they can't communicate with C programs and I've read that Streams are everything but efficient. (2) The following is an extract from the client program. It compiles and works as it is. May you please explain how to modify it in order to use the above-mentioned functions in place of Input() and Output()? If the problem can be solved by copying Strings to Stream_Element_Array and back, how can I do that? -- file client.adb with GNAT.Sockets, Ada.Text_IO, Ada.Strings.Unbounded, Ada.Command_Line; use GNAT.Sockets, Ada.Text_IO, Ada.Strings.Unbounded, Ada.Command_Line; procedure Client is Socket : Socket_Type; Address : Sock_Addr_Type; Channel : Stream_Access; Reply : Unbounded_String; begin Initialize; Create_Socket( Socket ); Address.Addr := Inet_Addr( "127.0.0.1" ); Address.Port := 9876; Connect_Socket( Socket, Address ); Channel := Stream( Socket ); if Argument_Count > 0 then if Argument(1) = "kill" then Put_Line( "asking server to shutdown" ); String'Output( Channel, "kill" ); else Put_Line( "sending """ & Argument( 1 ) & """" ); String'Output( Channel, Argument( 1 ) ); end if; Reply := Unbounded_String'Input( Channel ); Put_Line( "server echos """ & To_String( Reply ) & """" ); end if; Free( Channel ); Close_Socket( Socket ); Finalize; end Client; -- end of client.adb Thanks to all of you who will reply. fabio de francesco