* Re: GNAT.sockets UDP Example
@ 2002-11-17 13:26 David C. Hoos, Sr.
2002-11-18 8:09 ` arvids lemchens
0 siblings, 1 reply; 7+ messages in thread
From: David C. Hoos, Sr. @ 2002-11-17 13:26 UTC (permalink / 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
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT.sockets UDP Example
2002-11-17 13:26 GNAT.sockets UDP Example David C. Hoos, Sr.
@ 2002-11-18 8:09 ` arvids lemchens
0 siblings, 0 replies; 7+ messages in thread
From: arvids lemchens @ 2002-11-18 8:09 UTC (permalink / raw)
Hello David,
david.c.hoos.sr@ada95.com am 17.11.02 um 07:26 in comp.lang.ada:
> The compiler messages mean exactly what they say. You need to
> read and understand them.
I know, i am still learning.
> 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);
That was my first attempt, later i switched to the three-parameter as
i get more and more confused about two different Send_Socket's in
GNAT.Sockets.
> where Last has been declared as:
> Last : Ada.Streams.Stream_Element_Offset;
Thanks, that helped.
Now it compiles and Datagrams work.
MvfG,
Arvids
^ permalink raw reply [flat|nested] 7+ messages in thread
* GNAT.sockets UDP Example
@ 2002-11-15 21:48 arvids lemchens
2002-11-16 11:27 ` David C. Hoos, Sr.
0 siblings, 1 reply; 7+ messages in thread
From: arvids lemchens @ 2002-11-15 21:48 UTC (permalink / raw)
Hello,
i am looking for a very short and simple example how to send an
(empty) UDP-datagram with GNAT (3.14p, Linux).
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".
MvfG,
Arvids
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT.sockets UDP Example
2002-11-15 21:48 arvids lemchens
@ 2002-11-16 11:27 ` David C. Hoos, Sr.
2002-11-17 11:29 ` arvids lemchens
0 siblings, 1 reply; 7+ messages in thread
From: David C. Hoos, Sr. @ 2002-11-16 11:27 UTC (permalink / raw)
----- Original Message -----
From: "arvids lemchens" <lemchens@lemmies.lb.bawue.de>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: November 15, 2002 3:48 PM
Subject: GNAT.sockets UDP Example
> Hello,
>
> i am looking for a very short and simple example how to send an
> (empty) UDP-datagram with GNAT (3.14p, Linux).
>
> 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.
One guess -- did you create your socket like this?
Create_Socket (Socket, Family_Inet, Socket_Datagram);
How do you know that you didn't send correctly? Could the problem
be on the receiving end?
What platform/OS are you using?
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT.sockets UDP Example
2002-11-16 11:27 ` David C. Hoos, Sr.
@ 2002-11-17 11:29 ` arvids lemchens
2002-11-17 12:38 ` Simon Wright
0 siblings, 1 reply; 7+ messages in thread
From: arvids lemchens @ 2002-11-17 11:29 UTC (permalink / raw)
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));
-- 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT.sockets UDP Example
2002-11-17 11:29 ` arvids lemchens
@ 2002-11-17 12:38 ` Simon Wright
2002-11-18 8:24 ` arvids lemchens
0 siblings, 1 reply; 7+ messages in thread
From: Simon Wright @ 2002-11-17 12:38 UTC (permalink / raw)
lemchens@lemmies.lb.bawue.de (arvids lemchens) writes:
> 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"
I don't know what you think this means -- if you look at the spec of
Send_Socket it says
procedure Send_Socket
(Socket : Socket_Type;
Item : Ada.Streams.Stream_Element_Array;
Last : out Ada.Streams.Stream_Element_Offset);
-- Transmit a message to another socket. Note that Last is set to
-- Item'First when socket has been closed by peer. This is not an
-- error and no exception is raised. Raise Socket_Error on error;
Last is an *out* parameter, which means you need to supply an actual
variable of the correct type.
Kahnung : Ada.Streams.Stream_Element_Array := (1, 2, 3);
Last : Ada.Streams.Stream_Element_Offset;
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, Last);
> 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
When I correct this error I get (GCC-3.2, compiling with -bargs -E):
smaug.pushface.org[15]$ ./myrdate myrouter
Execution terminated by unhandled exception
Exception name: GNAT.SOCKETS.SOCKET_ERROR
Message: [107] Transport endpoint is not connected
Call stack traceback locations:
0x8062e3d 0x806350d 0x804a6d3 0x804a4f2 0x4003d27e
and I suspect maybe you need to call Bind_Socket??? -- hmm, now I get
smaug.pushface.org[16]$ ./myrdate myrouter
Execution terminated by unhandled exception
Exception name: GNAT.SOCKETS.SOCKET_ERROR
Message: [13] Permission denied
whereas
Send_Socket (Socket, Kahnung, Last, Address);
ends up with a constraint error. Oh well, I guess I need to get GDB
working now ...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT.sockets UDP Example
2002-11-17 12:38 ` Simon Wright
@ 2002-11-18 8:24 ` arvids lemchens
0 siblings, 0 replies; 7+ messages in thread
From: arvids lemchens @ 2002-11-18 8:24 UTC (permalink / raw)
Hello Simon,
simon@pushface.org am 17.11.02 um 12:38 in comp.lang.ada:
> lemchens@lemmies.lb.bawue.de (arvids lemchens) writes:
> Kahnung : Ada.Streams.Stream_Element_Array := (1, 2, 3);
> Last : Ada.Streams.Stream_Element_Offset;
the Last was missing.
After adding it, the code compiles and works.
Here is the working version (May be it helps someone who is searching
for a short, simple example too.):
-----
with GNAT.Sockets; use GNAT.Sockets;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Streams; use Ada.Streams;
procedure myrdate is
Address : Sock_Addr_Type;
Socket : Socket_Type;
Kahnung : Ada.Streams.Stream_Element_Array := (1, 2, 3, 4);
Last : Ada.Streams.Stream_Element_Offset;
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);
Send_Socket (Socket, Kahnung, Last, Address);
Receive_Socket (Socket, Kahnung, Last);
Close_Socket(Socket);
Finalize;
end myrdate;
-----
> Send_Socket (Socket, Kahnung, Last, Address);
> ends up with a constraint error. Oh well, I guess I need to get GDB
> working now ...
In the original posted code there was some garbage left, which should
be removed, like the channel and RTime, ...
MvfG,
Arvids
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2002-11-18 8:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-17 13:26 GNAT.sockets UDP Example David C. Hoos, Sr.
2002-11-18 8:09 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox