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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f0972757f30880f7,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-11 10:40:00 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: benjamin_place@hotmail.com (Benjamin Place) Newsgroups: comp.lang.ada Subject: Sockets - newbie at a brick wall Date: 11 Dec 2002 10:40:00 -0800 Organization: http://groups.google.com/ Message-ID: NNTP-Posting-Host: 64.193.216.41 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1039632000 31076 127.0.0.1 (11 Dec 2002 18:40:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 11 Dec 2002 18:40:00 GMT Xref: archiver1.google.com comp.lang.ada:31700 Date: 2002-12-11T18:40:00+00:00 List-Id: I'm looking for some help writing my first sockets (GNAT.Sockets) app - there must be something basic that I'm missing. I start my app My_Server (my_server.adb, below) on newton, then start My_Client (my_client.adb, below) on einstein. Einstein immediately reports an error, ben@einstein ben 01:12pm $ ./my_client raised GNAT.SOCKETS.SOCKET_ERROR : [56] Socket is already connected So what am I doing wrong. Which socket is already connected, and what should I do differently? I'm using GNATMAKE 5.00w (20010924) (gcc 3.1) on MacOS 10.1.5. Thanks for any help, Ben -- my_server.adb 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 -- 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 ("newton.cannella.org"), 1); Address.Port := 4134; -- Server should bind the address to the socket Bind_Socket (Socket, Address); Channel := Stream (Socket, Address); declare Message : String := String'Input (Channel); begin Address := Get_Address (Channel); Put_Line (Message & " from " & Image (Address)); end; Shutdown_Socket (Socket); -- Disconnect socket Close_Socket (Socket); -- Close socket end My_Server; -- my_client.adb 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 -- 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 ("newton.cannella.org"), 1), Port => 4134, Family => Family_Inet ); Connect_Socket (Socket, Server); -- Make a connection to another socket which has the address of -- Server. Raise Socket_Error on error. Channel := Stream (Socket, Server); String'Output (Channel, "Hello, world!"); Close_Socket (Socket); end My_Client;