comp.lang.ada
 help / color / mirror / Atom feed
* Byte order writing to socket stream
@ 2002-05-17 15:18 The Darkelf
  2002-05-17 15:54 ` Robert L. Klungle
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: The Darkelf @ 2002-05-17 15:18 UTC (permalink / raw)


Hi, I have an Ada program with GNAT.Sockets that works fine when client
and server are in the same architecture. The problem is when client runs
on HP and the server on Intel, or viceversa.

It raises a STORAGE_ERROR exception, when it reads an array from the
socket stream. I guess the problem must be the byte order, so one solution
should be to write the size of the array(integer) and then the elements of
the array (strings), checking the integer byte order.

Can the conversion to the net standard be done "on the fly", as I do the
Stream'Output(stream,theArray), or it's necesary to manually output each
element?

If so, any suggestion for checking the architecture byte order and
ouputing it in some standard way?

May it be easier or better to just output the integer values as strings
(Integer'Image) ?

Thanks for your opinions and suggestions.

Alvaro J. Iradier Muro



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

* Re: Byte order writing to socket stream
  2002-05-17 15:18 Byte order writing to socket stream The Darkelf
@ 2002-05-17 15:54 ` Robert L. Klungle
  2002-05-17 16:10 ` David C. Hoos
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Robert L. Klungle @ 2002-05-17 15:54 UTC (permalink / raw)


The Darkelf wrote:

> Hi, I have an Ada program with GNAT.Sockets that works fine when client
> and server are in the same architecture. The problem is when client runs
> on HP and the server on Intel, or viceversa.
>
> It raises a STORAGE_ERROR exception, when it reads an array from the
> socket stream. I guess the problem must be the byte order, so one solution
> should be to write the size of the array(integer) and then the elements of
> the array (strings), checking the integer byte order.
>
> Can the conversion to the net standard be done "on the fly", as I do the
> Stream'Output(stream,theArray), or it's necesary to manually output each
> element?
>
> If so, any suggestion for checking the architecture byte order and
> ouputing it in some standard way?
>
> May it be easier or better to just output the integer values as strings
> (Integer'Image) ?
>
> Thanks for your opinions and suggestions.
>
> Alvaro J. Iradier Muro

FWIW, had the same problem a while ago.
CORBA was an option (complex fix).
Doing byte swapping assumes apriori knowledge of incoming data format(s).
Did the string thing and all worked ok (although a little slower than otherwise).

cheers....bob




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

* Re: Byte order writing to socket stream
  2002-05-17 15:18 Byte order writing to socket stream The Darkelf
  2002-05-17 15:54 ` Robert L. Klungle
@ 2002-05-17 16:10 ` David C. Hoos
  2002-05-17 21:11 ` Ted Dennison
  2002-05-18  8:11 ` Dr. Michael Paus
  3 siblings, 0 replies; 9+ messages in thread
From: David C. Hoos @ 2002-05-17 16:10 UTC (permalink / raw)



----- Original Message ----- 
From: "The Darkelf" <darkelf@aim.homelinux.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Friday, May 17, 2002 10:18 AM
Subject: Byte order writing to socket stream
<snip>
> If so, any suggestion for checking the architecture byte order and
> ouputing it in some standard way?
> 
I would use the package body of System.Stream_Attributes that
comes with glade (the Annex E implementation of GNAT)
(file name is s-stratt.adb) which modifies the stream attributes of
the numeric types to use the XDR network format.

You can compile this into your GNAT runtime and rebuild it.

 




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

* Re: Byte order writing to socket stream
  2002-05-17 15:18 Byte order writing to socket stream The Darkelf
  2002-05-17 15:54 ` Robert L. Klungle
  2002-05-17 16:10 ` David C. Hoos
@ 2002-05-17 21:11 ` Ted Dennison
  2002-05-18  6:47   ` Simon Wright
  2002-05-18  8:11 ` Dr. Michael Paus
  3 siblings, 1 reply; 9+ messages in thread
From: Ted Dennison @ 2002-05-17 21:11 UTC (permalink / raw)


The Darkelf <darkelf@aim.homelinux.com> wrote in message news:<ac36va$m6qca$1@ID-107015.news.dfncis.de>...
> Hi, I have an Ada program with GNAT.Sockets that works fine when client
> and server are in the same architecture. The problem is when client runs
> on HP and the server on Intel, or viceversa.

You may want to look into using Gnat's Annex E support (GLADE), which
I believe deals with this issue *and* the communications issue. Both
sides have to be Ada, though.

-- 
T.E.D. 
Home     -  mailto:dennison@telepath.com (Yahoo: Ted_Dennison)
Homepage -  http://www.telepath.com/dennison/Ted/TED.html



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

* Re: Byte order writing to socket stream
  2002-05-17 21:11 ` Ted Dennison
@ 2002-05-18  6:47   ` Simon Wright
  2002-05-18  8:09     ` David C. Hoos, Sr.
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Wright @ 2002-05-18  6:47 UTC (permalink / raw)


dennison@telepath.com (Ted Dennison) writes:

> You may want to look into using Gnat's Annex E support (GLADE),
> which I believe deals with this issue *and* the communications
> issue. Both sides have to be Ada, though.

Clearly you could go to a lot to trouble to write C which understands
what GLADE does.

I don't know whether ACT make any guarantees about the stability of
the wire format used by their Annex E support between releases; to be
safe you might want to use the same release both ends.

You'd be most unlikely to get interoperability with other Ada
compilers (even if you could find one with Annex A support).



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

* Re: Byte order writing to socket stream
  2002-05-18  6:47   ` Simon Wright
@ 2002-05-18  8:09     ` David C. Hoos, Sr.
  2002-05-18 17:09       ` Simon Wright
  0 siblings, 1 reply; 9+ messages in thread
From: David C. Hoos, Sr. @ 2002-05-18  8:09 UTC (permalink / raw)



----- Original Message ----- 
From: "Simon Wright" <simon@pushface.org>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: May 18, 2002 1:47 AM
Subject: Re: Byte order writing to socket stream


<snip>
> 
> I don't know whether ACT make any guarantees about the stability of
> the wire format used by their Annex E support between releases; to be
> safe you might want to use the same release both ends.
>
GNAT implements the XDR spec, so it should be the same between releases.
 
> You'd be most unlikely to get interoperability with other Ada
> compilers (even if you could find one with Annex A support).
>
They all are required to have Annex A support.  Did you mean Annex E?






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

* Re: Byte order writing to socket stream
  2002-05-17 15:18 Byte order writing to socket stream The Darkelf
                   ` (2 preceding siblings ...)
  2002-05-17 21:11 ` Ted Dennison
@ 2002-05-18  8:11 ` Dr. Michael Paus
  2002-05-18 20:30   ` Robert Dewar
  3 siblings, 1 reply; 9+ messages in thread
From: Dr. Michael Paus @ 2002-05-18  8:11 UTC (permalink / raw)


The Darkelf wrote:
> Hi, I have an Ada program with GNAT.Sockets that works fine when client
> and server are in the same architecture. The problem is when client runs
> on HP and the server on Intel, or viceversa.
> 
> It raises a STORAGE_ERROR exception, when it reads an array from the
> socket stream. I guess the problem must be the byte order, so one solution
> should be to write the size of the array(integer) and then the elements of
> the array (strings), checking the integer byte order.
> 
> Can the conversion to the net standard be done "on the fly", as I do the
> Stream'Output(stream,theArray), or it's necesary to manually output each
> element?
> 
> If so, any suggestion for checking the architecture byte order and
> ouputing it in some standard way?
> 
> May it be easier or better to just output the integer values as strings
> (Integer'Image) ?
> 
> Thanks for your opinions and suggestions.
> 
> Alvaro J. Iradier Muro

Hi,

you could download my package
http://www.ib-paus.com/downloads/AdaStreamsInNetworkByteOrder_020326.tar.gz
and use it with your program. This will automatically convert all data
into network byte order, so that you can work with mixed architectures.
This is a modified version of a standard GNAT package and so only works
with GNAT.

Hope this helps

Michael




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

* Re: Byte order writing to socket stream
  2002-05-18  8:09     ` David C. Hoos, Sr.
@ 2002-05-18 17:09       ` Simon Wright
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Wright @ 2002-05-18 17:09 UTC (permalink / raw)


"David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:

> GNAT implements the XDR spec, so it should be the same between releases.

That's good

> > You'd be most unlikely to get interoperability with other Ada
> > compilers (even if you could find one with Annex A support).
> 
> They all are required to have Annex A support.  Did you mean Annex E?

of course, stupid mistake, sorry



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

* Re: Byte order writing to socket stream
  2002-05-18  8:11 ` Dr. Michael Paus
@ 2002-05-18 20:30   ` Robert Dewar
  0 siblings, 0 replies; 9+ messages in thread
From: Robert Dewar @ 2002-05-18 20:30 UTC (permalink / raw)


"Dr. Michael Paus" <paus@ib-paus.com> wrote in message news:<3CE60CAC.7020102@ib-paus.com>...
> you could download my package ...

You could also use the GLADE version of s-stratt.ads/adb



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

end of thread, other threads:[~2002-05-18 20:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-17 15:18 Byte order writing to socket stream The Darkelf
2002-05-17 15:54 ` Robert L. Klungle
2002-05-17 16:10 ` David C. Hoos
2002-05-17 21:11 ` Ted Dennison
2002-05-18  6:47   ` Simon Wright
2002-05-18  8:09     ` David C. Hoos, Sr.
2002-05-18 17:09       ` Simon Wright
2002-05-18  8:11 ` Dr. Michael Paus
2002-05-18 20:30   ` Robert Dewar

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