Sockets
David Kramer
david at thekramers.net
Sat Oct 16 23:26:01 EDT 2004
Anthony Gabrielson wrote, On 10/16/2004 08:59 PM:
> Hello,
> I'm looking for a sockets example that isn't an echo server...
> I'm looking for an example that sends an interger, or a Struct, something
> non char. Does anyone have a link or advice?
Just like saving an object in memory to a file, or any other stream, it must
be serialized: flattened into a bytestream. In the case of streams sent
between different computers, you usually want to send the data in a way that
will be platform-independent. That means if you want to send an int, you don't
just send the int through, because the other side may have a different size
int, or not be two's complement, or a different endianness, or whatever. So
it's common to send strings.
If you really want to send unserialized data, there's nothing stopping you.
You'll notice that read() and write() take a void*. To send integers as
integers, just pass a int* instead of a char*. The rest of your code remains
the same, and sizeof(int) for the third parameter.
----------------------------------------------------------------------------
DDDD David Kramer david at thekramers.net http://thekramers.net
DK KD
DKK D Love to stay. Can't. Have to go. Kiss kiss, love love, bye.
DK KD
DDDD J'Kar
More information about the Discuss
mailing list