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, 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-12 06:19:09 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!colt.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: john@nospam.assen.demon.co.uk (John McCabe) Newsgroups: comp.lang.ada Subject: Re: Sockets - newbie at a brick wall Date: Thu, 12 Dec 2002 14:19:49 GMT Message-ID: <3df895c0.17679291@news.demon.co.uk> References: <3df85d10.3167644@news.demon.co.uk> NNTP-Posting-Host: pipehawk.demon.co.uk X-Trace: news.demon.co.uk 1039702749 22660 158.152.226.81 (12 Dec 2002 14:19:09 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Thu, 12 Dec 2002 14:19:09 +0000 (UTC) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:31740 Date: 2002-12-12T14:19:49+00:00 List-Id: On Thu, 12 Dec 2002 09:58:25 GMT, john@assen.nospam.demon.co.uk (John McCabe) wrote: >On 11 Dec 2002 10:40:00 -0800, benjamin_place@hotmail.com (Benjamin >Place) wrote: > >>So what am I doing wrong. Which socket is already connected, and what >>should I do differently? > >To be honest, I haven't used GNAT.Sockets, but two things strike me as >odd: > >1) Your use of Socket_Datagram with a Connect() call. Perhaps you >should try Socket_Stream sockets. Datagrams are 'connectionless' sockets so you wouldn't use the Connect() call at all. >2) Should there be a call to Listen() on the server side or is that >included in one of the other calls? Listen()/Accept() is only applicable to Stream sockets. I've now had the chance to look at GNAT.Sockets. First thing is that I would try starting with a simplified version of the stream sockets example in g-socket.ads. However, if you want to use datagrams, you could use the datagram part of the example but ditch the multicast stuff for the moment. For what it's worth, I've modified your files based on the example in g-socket.ads. See below. Hope this helps. -- my_client.adb with GNAT.Sockets; use GNAT.Sockets; procedure My_Client is Socket : Socket_Type; Address : Sock_Addr_Type; Channel : Stream_Access; begin -- Initialise the socket bindings. Initialize (Process_Blocking_IO => False); Create_Socket (Socket, Family_Inet, Socket_Datagram); Set_Socket_Option (Socket, Socket_Level, (Reuse_Address, True)); Address.Addr := Addresses (Get_Host_By_Name ("newton.cannella.org"), 1); Address.Port := 4134; Bind_Socket (Socket, Address); Channel := Stream (Socket, Address); -- Send message to server. String'Output (Channel, "Hello world"); Close_Socket (Socket); end My_Client; -- 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; begin -- Initialise the socket bindings. Initialize (Process_Blocking_IO => False); Create_Socket (Socket, Family_Inet, Socket_Datagram); -- Allow reuse of local addresses. Set_Socket_Option (Socket, Socket_Level, (Reuse_Address, True)); -- If this socket is intended to receive messages, bind it to a -- given socket address. Address.Addr := Any_Inet_Addr; Address.Port := 4134; Bind_Socket (Socket, Address); Channel := Stream (Socket, Address); -- Receive and print message from client. declare Message : String := String'Input (Channel); begin -- Get the address of the sender. Address := Get_Address (Channel); Ada.Text_IO.Put_Line (Message & " from " & Image (Address)); end; Close_Socket (Socket); end My_Server;