Re: Socket programming

Glynn Clements <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
Ardhan Madras wrote:

> I was written small network utility in Linux 2.6, glibc 2.7.
> I have been using send() and recv() system call in SOCK_STREAM
> to send or receive fixed size data. for example, i write my data 
> structure like this:
> 
> struct foo
> {
>   char name[16];
>   char pix[1024];
>   int id;
> } bar;
> 
> If i want to send or receive data i just call
> 
> send (socket, &bar, sizeof(struct foo), 0);
> 
> or to receive:
> recv (socket, &bar, sizeof(struct foo), 0);

Apart from the comments which have already been made:

There's no reason to use send() and recv() if the flags argument is
zero. You may as well use read() and write(). Or convert the
descriptor to a FILE* with fdopen() and use fread() and fwrite().

-- 
Glynn Clements <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.