comp.lang.ada
 help / color / mirror / Atom feed
* gnat sockets problem
@ 2004-05-30  0:08 wave
  2004-05-30  2:30 ` tmoran
  2004-05-30 11:06 ` Simon Wright
  0 siblings, 2 replies; 3+ messages in thread
From: wave @ 2004-05-30  0:08 UTC (permalink / raw)


Hi, I apologise that yet again I ask this newsgroup another question,
but I've exhausted google and all the resources I could find on this
subject!

I'm having a problem, basically I'm wanting to write an ada program to
return a raw quake3 server string. If any of you know how this works,
it's over udp and you're sending the server a basic keyword command
and then it responds timely to your request.

Here's the problem; in my code the server is only giving me back 4
characters of the response the server should give, and I can't figure
out why. I wondered if any of you lovely people could shed some light
on this issue if you have any experience in this area.

Here is my code below:

with Gnat.Sockets; use Gnat.Sockets;
with Ada.Text_Io; use Ada.Text_Io;

procedure meh is 
   Socket  : Socket_Type;  
   Server  : Sock_Addr_Type;  
   Channel : Stream_Access;
begin

   Initialize;
   Create_Socket (Socket, Family_Inet, Socket_Datagram);

-- Functioning ip address of a server I'm trying to query
   Server := (
      Addr => Addresses (Get_Host_By_Name ("216.12.23.248"), 1),
      Port => 27960,
      Family => Family_Inet
      );

 Bind_Socket (Socket, Server);

 Connect_Socket (Socket, Server);  
 Channel := Stream (Socket);

-- tried Character'Val(255) instead of � too! 
 String'Output (Channel,"����getstatus");

    loop
      declare
  Message : String := String'Input (Channel);
      begin
         Put (Message);
      end;
   end loop;


 Close_Socket (Socket);
end meh;

It all goes so well up until a point, but instead of the server
responding with "����statusResponse.\game_version\sof2mp-1.02\sv_keywords\SOF2FULL.\sv_pure\1\......"
I'm only just getting the ����.
Is there some limit to the amount of data ada can send back or
something?

There are some quake3 protocol specs here:
http://www.game-tracker.com/gameproto/enemyterritory.htm (et is just a
mod for q3, same concept) that should show how the server should
behave in this situation.

As always, I'm really helpful for any insight you can give me.

Cheers guys.



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

* Re: gnat sockets problem
  2004-05-30  0:08 gnat sockets problem wave
@ 2004-05-30  2:30 ` tmoran
  2004-05-30 11:06 ` Simon Wright
  1 sibling, 0 replies; 3+ messages in thread
From: tmoran @ 2004-05-30  2:30 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 705 bytes --]

>String'Output (Channel,"����getstatus");
  In the definition of 'Output, ARM 13.13.2(21) says
"S'Output writes the value of Item to Stream, including any bounds or
discriminants."  So you are probably sending 4 bytes containing the
integer 1 (the lower bound of the string you are sending), then the
integer 13 (the upper bound), followed the 13 bytes you think you are
sending.  Similarly 'Input expects to read the bounds, then the
data.  Using 'Write instead of 'Output will probably solve the sending
problem, but S'Read is a procedure, not a function, since YOU will have
to supply the bounds, which presumably you can get from the recv (or
whatever gnat.sockets uses for datagram input).



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

* Re: gnat sockets problem
  2004-05-30  0:08 gnat sockets problem wave
  2004-05-30  2:30 ` tmoran
@ 2004-05-30 11:06 ` Simon Wright
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Wright @ 2004-05-30 11:06 UTC (permalink / raw)


mutilation@bonbon.net (wave) writes:

>     loop
>       declare
>          Message : String := String'Input (Channel);
>       begin
>          Put (Message);
>       end;
>    end loop;

Tom has given you a suggestion for the send part.

For the receive part, you need to read the whole datagram at one go,
so you mustn't use the stream attributes ('Read, 'Input even) on a
network socket stream (for a record type, each non-elementary
component of the stream ends up in a recvFrom() from the socket!).

The same is true in reverse for 'Write; avoid it for UDP!

Instead, use GNAT.Sockets.Receive_Socket (I've used the second form
when receiving UDP messages):

   procedure Receive_Socket
     (Socket : Socket_Type;
      Item   : out Ada.Streams.Stream_Element_Array;
      Last   : out Ada.Streams.Stream_Element_Offset;
      From   : out Sock_Addr_Type);

to read into a Stream_Element_Array of the appropriate maximum size
you are expecting; no harm really in choosing the max size of a UDP
datagram, 1500 bytes or so, unless Quake uses a smaller max size.

Once you have the Stream_Element_Array you can read the bounds etc
from it and use unchecked conversion (or overlay) to get at the actual
fields.

-- 
Simon Wright                               100% Ada, no bugs.



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

end of thread, other threads:[~2004-05-30 11:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-30  0:08 gnat sockets problem wave
2004-05-30  2:30 ` tmoran
2004-05-30 11:06 ` Simon Wright

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