comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: GNAT.sockets UDP Example
Date: Sun, 17 Nov 2002 07:26:52 -0600
Date: 2002-11-17T07:26:52-06:00	[thread overview]
Message-ID: <mailman.1037539683.14063.comp.lang.ada@ada.eu.org> (raw)

"arvids lemchens" <lemchens@lemmies.lb.bawue.de> wrote in message
news:8a2dx5TkACB@lemmies.lb.bawue.de...
> Hello David,
>
> david.c.hoos.sr@ada95.com am 16.11.02 um 05:27 in comp.lang.ada:
> > ----- Original Message -----
> > From: "arvids lemchens" <lemchens@lemmies.lb.bawue.de>
> >> Found one for TCP, but didn't get it to switch to UDP.
> >> Somehow it seems that i am to simpleminded for the "Send_Socket".
> > It's hard to guess what you might be doing wrong, without your code.
>
> Ok, stripped my code to the essentials:
>
> -----
> with GNAT.Sockets; use GNAT.Sockets;
> with GNAT.Calendar.Time_IO; use GNAT.Calendar.Time_IO;
> with Ada.Text_IO;
> with Ada.Command_Line; use Ada.Command_Line;
> with Ada.Exceptions; use Ada.Exceptions;
> with Ada.Calendar; use Ada.Calendar;
> with Interfaces; use Interfaces;
> with Ada.Streams; use Ada.Streams;
>
> procedure myrdate is
>     Address  : Sock_Addr_Type;
>     Socket   : Socket_Type;
>     Channel  : Stream_Access;
>     LTime    : Time;
>     RTime    : Unsigned_32;
>     SockRet  : Integer;
>     Kahnung  : Ada.Streams.Stream_Element_Array := (1, 2, 3);
>
> begin
>     Initialize (Process_Blocking_IO => False);
>     Address.Addr := Addresses (Get_Host_By_Name(Argument(1)), 1);
>     Address.Port := 37;
>     Create_Socket (Socket, Family_Inet, Socket_Datagram);
>     --  Rest from TCP
>     --    Connect_Socket (Socket, Address);
>     --    Channel := Stream (Socket);
>     Send_Socket (Socket, Kahnung, Kahnung(2));
The compiler messages mean exactly what they say.  You need to
read and understand them.

For a connectionless socket, you need the four-parameter version of
Send_Socket, otherwise the destination address is unspecified,
so you need

      Send_Socket (Socket, Kahnung, Last, Address);

where Last has been declared as:
    Last     : Ada.Streams.Stream_Element_Offset;

You really need to read and understand the GNAT>Sockets specification,
and the comments which accompany each item.

>     --  Here should come Receive_Socket
>     LTime := Clock;
>     RTime := Unsigned_32'Input (Channel);
>     --  Here should come Bitmanipulation
>     Close_Socket(Socket);
>     Finalize;
> end myrdate;
> -----
>
> If i try to compile it:
>
> -----
> ich@pc3:/transfer/ich2/ada/my/myrdate$ gnatmake -gnatf sendudp.adb
> gnatgcc -c -gnatf sendudp.adb
> sendudp.adb:10:11: warning: file name does not match unit name, should be "myrdate.adb"
> sendudp.adb:27:05: no candidate interpretations match the actuals:
> sendudp.adb:27:05: missing argument for parameter "To" in call to "send_socket" declared at
g-socket.ads:653
> sendudp.adb:27:35: expected type "Ada.Streams.Stream_Element_Offset"
> sendudp.adb:27:35: found type "Ada.Streams.Stream_Element"
> sendudp.adb:27:35:   ==> in call to "Send_Socket" at g-socket.ads:645
> gnatmake: "sendudp.adb" compilation error
> ich@pc3:/transfer/ich2/ada/my/myrdate$
> -----
>
> also tried different variants of the Send_Socket, but always there are
> (different) errors.
>
> Seems that i am missing some elementary knowledge about streams.
>
> > One guess -- did you create your socket like this?
> > Create_Socket (Socket, Family_Inet, Socket_Datagram);
>
> That part is ok.
>
> > How do you know that you didn't send correctly?  Could the problem
> > be on the receiving end?
>
> No, it even doesn't compile. The Network itself is fine.
>
> > What platform/OS are you using?
>
> Linux.
>
> > I have used GNAT sockets for TCP, UDP (broadcast and point-to-point),
> > and multicast with great success, by none of my examples is short or
> > simple.
>
> Confusing too, i found that there seems to be two different
> Send_Socket's in GNAT-Sockets (using send and sendto).
>
> How do i know which the Compiler will use?
>
> Meanwhile i realized that also the Part with the Bitmanipulation is
> too complicated, at least for my current level of knowledge.
>
> So i am starting to think about some easier "Learning-by-doing"-
> exercises for me and leave the rdate for later.
>
> But if it is only a little modification do get above code running
> i would be appreciate for seeing possibel corrections.
>
> Thanks in advance.
>
> MvfG,
>
> Arvids
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
>





             reply	other threads:[~2002-11-17 13:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-17 13:26 David C. Hoos, Sr. [this message]
2002-11-18  8:09 ` GNAT.sockets UDP Example arvids lemchens
  -- strict thread matches above, loose matches on Subject: below --
2002-11-15 21:48 arvids lemchens
2002-11-16 11:27 ` David C. Hoos, Sr.
2002-11-17 11:29   ` arvids lemchens
2002-11-17 12:38     ` Simon Wright
2002-11-18  8:24       ` arvids lemchens
replies disabled

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