Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sockets



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




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org