comp.lang.ada
 help / color / mirror / Atom feed
* TCP/IP Sockets with GNAT.Sockets
@ 2005-05-02  2:42 fabio de francesco
  2005-05-02  5:58 ` Eric Jacoboni
  2005-05-02 12:11 ` Adrien Plisson
  0 siblings, 2 replies; 25+ messages in thread
From: fabio de francesco @ 2005-05-02  2:42 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 25+ messages in thread
[parent not found: <mailman.112.1115585537.24457.comp.lang.ada@ada-france.org>]
* Re: Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets)
@ 2005-05-15  2:42 Frank Beard
  0 siblings, 0 replies; 25+ messages in thread
From: Frank Beard @ 2005-05-15  2:42 UTC (permalink / raw)
  To: Manuel G. R., comp.lang.ada

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 1720 bytes --]

Well, I was actually talking about what is really
referred to as the Extended ASCII set:

http://www.computerhope.com/jargon/a/ascii.htm
or
http://www.lookuptables.com/

Maybe I've just been working in the Windows world too
long:

http://telecom.tbi.net/asc-ibm.html

Frank


--- "Manuel G. R." <mgrojo@ya.com> wrote:
> Frank Beard wrote:
> > The ASCII package became one of the "Obsolescent
> Features" before the 
> > ASCII standard was expanded from 128 to 256
> characters.  Even if it 
> > didn't expand, it would probably never be gone
> from the Ada standard, 
> > for backward compatibility reasons.  The only risk
> would be trying to go 
> > beyond character'pos = 127.
> >  
> > Now that the ASCII standard is expanded, there's
> probably no reason not 
> > to use it.  But, if you're worried about it you
> can just do the rename 
> > as*/ /*Adrien pointed out in his reply.
> >  
> 
> ASCII is a 7 bit character set and never was
> expanded to 256 characters. 
> You are probably refering to one of its supersets,
> e.g. Latin 1 (ISO 8859-1)
> 
> http://en.wikipedia.org/wiki/ASCII
> http://en.wikipedia.org/wiki/ISO_8859
> 
> But I think you are right, ASCII package should
> never leave the standard.
> 
> -- 
> Ada programming tutorial:
> http://en.wikibooks.org/wiki/Programming:Ada
> Tutorial de programaci�n en Ada: 
>
http://es.wikibooks.org/wiki/Programaci%C3%B3n_en_Ada
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
>
http://www.ada-france.org/mailman/listinfo/comp.lang.ada
> 


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 



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

end of thread, other threads:[~2005-05-15  2:42 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-02  2:42 TCP/IP Sockets with GNAT.Sockets fabio de francesco
2005-05-02  5:58 ` Eric Jacoboni
2005-05-02 12:11 ` Adrien Plisson
2005-05-02 14:55   ` fabio de francesco
2005-05-02 16:10     ` Adrien Plisson
2005-05-02 17:56       ` Eric Jacoboni
2005-05-02 18:30         ` Poul-Erik Andreasen
2005-05-02 19:10           ` Simon Wright
2005-05-03 13:00             ` Poul-Erik Andreasen
2005-05-03 21:48               ` Simon Wright
2005-05-04  8:01               ` Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets) Adrien Plisson
2005-05-04 13:40                 ` Poul-Erik Andreasen
2005-05-02 20:37           ` TCP/IP Sockets with GNAT.Sockets fabio de francesco
2005-05-02 20:52             ` Adrien Plisson
2005-05-03 12:04               ` fabio de francesco
2005-05-03 12:22                 ` Adrien Plisson
2005-05-03 13:17             ` Poul-Erik Andreasen
2005-05-02 20:44         ` Adrien Plisson
2005-05-02 22:10           ` Eric Jacoboni
2005-05-02 23:42             ` tmoran
2005-05-02 19:39     ` Björn
2005-05-02 20:22       ` fabio de francesco
2005-05-09  4:03         ` Dave Thompson
     [not found] <mailman.112.1115585537.24457.comp.lang.ada@ada-france.org>
2005-05-09 20:59 ` Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets) Manuel G. R.
  -- strict thread matches above, loose matches on Subject: below --
2005-05-15  2:42 Frank Beard

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