[Gambas-user] gb3 RC1: using structures to replace the loss of Mk$ functions
Doriano Blengino
doriano.blengino at ...1909...
Sun Apr 3 22:51:53 CEST 2011
Il 03/04/2011 22:07, Kevin Fishburne ha scritto:
> On 04/03/2011 02:27 PM, Benoît Minisini wrote:
>
>> OK... I should have read all that more carefully, as I have said rubbish.
>>
>> Sending a message to an UDP socket can only be done with a string or a
>> structure. If you use several WRITE instructions, you will get one message by
>> WRITE. Not a good thing...
>>
>> So my answer about object-oriented programming is useless. Or at least it will
>> help you to understand what object-oriented programming is.
>>
> I appreciate the explanation. It's definitely something I need to learn
> more about if I want to grow as a programmer.
>
>
>> So now ? I think I have to think... The problem with Mk*() functions is their
>> endianness dependency. Maybe I can make these functions endianness-aware, but
>> it is not a immediate job.
>>
> For endianness to matter the client and server programs would have to
> have different endiannesses and the program receiving the UDP string
> would have to be converting the string back into variables using
> functions like Single@ or equivalents. If the sender was big-endian and
> the receiver was little-endian then the bit order would be backward on
> the receiving end and thus an unexpected value.
>
Well, typically this is solved by macros like "hton" in the C library.
This macro inverts the bytes on little endian machines, and does nothing
on big endian machines. The Internet is big endian, if I well remember -
i.e., it surely transfers the MSB first. It would suffice that the
Gambas WRITE instruction swapped the bytes if the machine is little
endian, like Intel machines, if data type is word, integer, long or float.
In order to produce a single packet from several fields, they could be
specified on a single WRITE, or a semicolon could be used as separator
like in the PRINT instruction.
Just a thought,
regards,
--
Doriano Blengino
"Listen twice before you speak.
This is why we have two ears, but only one mouth."
More information about the User
mailing list