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, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f0972757f30880f7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-13 14:38:10 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: benjamin_place@hotmail.com (Benjamin Place) Newsgroups: comp.lang.ada Subject: Re: Sockets - newbie at a brick wall Date: 13 Dec 2002 14:38:09 -0800 Organization: http://groups.google.com/ Message-ID: References: NNTP-Posting-Host: 67.36.79.140 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1039819089 18461 127.0.0.1 (13 Dec 2002 22:38:09 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 13 Dec 2002 22:38:09 GMT Xref: archiver1.google.com comp.lang.ada:31805 Date: 2002-12-13T22:38:09+00:00 List-Id: Simon Wright wrote in message news:... > You don't show any calls to GNAT.Sockets.Initialize. We found that > leaving out this call made no (apparent) difference on Linux, but that > it was necessary on Windows. No experience with MacOS! My code (version 2) works fine on OS X (or so it seems), but you're right, it fails on Windows. The following code (version 3) works on Windows. The default parameter on Windows is procedure Initialize (Process_Blocking_IO : Boolean := False); and this seems to work just fine. Oddly enough, though, the call Channel := Stream (Socket, Server) fails on Windows. The way I fixed it is to first call Connect_Socket (Socket, Server), and then to call Channel := Stream (Socket). The following code works on Windows, but has not been tested on Linux or OS X. Thanks for all the response! -- my_client.adb version 3 with GNAT.Sockets; use GNAT.Sockets; with Ada.Text_IO; use Ada.Text_IO; procedure My_Client is Socket : Socket_Type; Server : Sock_Addr_Type; Channel : Stream_Access; begin -- Initialize Sockets library Initialize; -- Create a client-side socket. Raise Socket_Error on error. Create_Socket (Socket, Family_Inet, Socket_Datagram); -- Initialize sockaddr_in structure with server (remote) socket name Server := ( Addr => Addresses (Get_Host_By_Name ("passport"), 1), Port => 4134, Family => Family_Inet ); Connect_Socket (Socket, Server); Channel := Stream (Socket); String'Output (Channel, "Hello, world!"); Close_Socket (Socket); end My_Client; -- my_server.adb version 3 with GNAT.Sockets; use GNAT.Sockets; with Ada.Text_IO; use Ada.Text_IO; procedure My_Server is Socket : Socket_Type; Address : Sock_Addr_Type; Channel : Stream_Access; Loop_Count : Natural := 0; begin -- Initialize Sockets library Initialize; -- Create an endpoint for communication. Raise Socket_Error on error. Create_Socket (Socket, Family_Inet, Socket_Datagram); -- Initialize sockaddr_in structure with server (local) socket name Address.Addr := Addresses (Get_Host_By_Name ("passport"), 1); Address.Port := 4134; -- Server should bind the address to the socket Bind_Socket (Socket, Address); Channel := Stream (Socket, Address); loop declare Message : String := String'Input (Channel); begin exit when Message = "q"; Address := Get_Address (Channel); Put_Line (Message & " from " & Image (Address)); end; end loop; Shutdown_Socket (Socket); -- Disconnect socket Close_Socket (Socket); -- Close socket end My_Server;