amish munshi writes:

Greetings,

I want to send a userdefined structure over a network, I would like to know if there is a way to convert a structure into string.

LANG - C++;
COMPILER - g++;

There is no need to convert a structure into a string. Trust the C library
to make it easy for you.


The following is an elegant solution

Here is a code snippet for you

#include <sys/uio.h>

// define a structure of type iovec
iovec iov[0];


// rtt_hdr is my header structure
// for RTT packet. Pass the base address
// and the size of the header


iov[0].iov_base = &rtt_hdr;
iov[0].iov_len = sizeof(rtt_hdr);


then use the readv/writev calls to read and write to the network
socket.


refer pg 357-358 of Unix Network programming - Richard Stevens Volume 1
( I am not qouting this from memory - just that I located the book nearby ;)


Also refer the manpages of readv / writev C library calls.

Vinayak Hegde
APGDST Student
NCST-JUHU

--


http://mm.ilug-bom.org.in/mailman/listinfo/linuxers

Reply via email to