comp.lang.ada
 help / color / mirror / Atom feed
* Sockets - newbie at a brick wall
@ 2002-12-11 18:40 Benjamin Place
  2002-12-12  9:58 ` John McCabe
  2002-12-13 11:31 ` Simon Wright
  0 siblings, 2 replies; 11+ messages in thread
From: Benjamin Place @ 2002-12-11 18:40 UTC (permalink / raw)


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;



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2002-12-16 10:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-11 18:40 Sockets - newbie at a brick wall Benjamin Place
2002-12-12  9:58 ` John McCabe
2002-12-12 14:19   ` John McCabe
2002-12-12 16:23     ` Toshitaka Kumano
2002-12-12 17:27       ` John McCabe
2002-12-13 11:25       ` John McCabe
2002-12-12 16:49   ` Benjamin Place
2002-12-13 11:31 ` Simon Wright
2002-12-13 13:52   ` John McCabe
2002-12-13 22:38   ` Benjamin Place
2002-12-16 10:16     ` John McCabe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox