linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ardhan Madras" <ajhwb@knac.com>
To: Canaan Kao <canaan.kao@gmail.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Socket programming
Date: Sun, 22 Mar 2009 06:31:16 -0700	[thread overview]
Message-ID: <20090322063116.1C31F627@resin17.mta.everyone.net> (raw)

Dear Canaan,

Thanks for your reply. It's a great clue :)
btw, i have one more question... 

In the receiver, do i need to allocate for example
bar->name member manually? or it's done by recv() ?


--- canaan.kao@gmail.com wrote:

From:	Canaan Kao <canaan.kao@gmail.com>
To:	ajhwb@knac.com
Cc:	linux-c-programming@vger.kernel.org
Subject: Re: Socket programming
Date:	Sun, 22 Mar 2009 21:00:14 +0800

Dear Ardhan,

You can add a mySize data member in struct foo.

struct foo
 {
  unsigned mySize;
  char *name;
  char *pix;
  int id;
 };


 struct foo *bar = malloc (sizeof(struct foo));

 if(NULL!=bar)bar->mySize=sizeof(struct foo);

 /* fill the structure, then send */

Finally, your receiver will get the size of foo in the beginning of the stream.

Best regards,
Canaan

On Sun, Mar 22, 2009 at 8:42 PM, Ardhan Madras <ajhwb@knac.com> wrote:
> Hi All,
>
> 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);
>
> My problem is how to receive dynamic sized data? for
> example this structure:
>
> struct foo
> {
>  char *name;
>  char *pix;
>  int id;
> }
>
> struct foo *bar = malloc (sizeof(struct foo));
> /* fill the structure, then send */
>
> How to receive the data? since there are no way
> to the receiver to know data sizes?
>
> Thanks for your help.
>
>
> _____________________________________________________________
> Listen to KNAC, Hit the Home page and Tune In Live! ---> http://www.knac.com
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html




_____________________________________________________________
Listen to KNAC, Hit the Home page and Tune In Live! ---> http://www.knac.com

             reply	other threads:[~2009-03-22 13:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-22 13:31 Ardhan Madras [this message]
2009-03-22 13:41 ` Socket programming Volker Kokula
2009-03-22 15:24 ` Canaan Kao
2009-03-26 21:42   ` Anil Vishnoi
  -- strict thread matches above, loose matches on Subject: below --
2009-03-23 15:03 Ardhan Madras
2009-03-22 15:47 Ardhan Madras
2009-03-22 14:08 Ardhan Madras
2009-03-22 15:04 ` Volker Kokula
2009-03-22 12:42 Ardhan Madras
2009-03-22 13:00 ` Canaan Kao
2009-03-22 18:39 ` Jon Mayo
2009-03-26 21:58   ` Anil Vishnoi
2009-03-23  9:18 ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090322063116.1C31F627@resin17.mta.everyone.net \
    --to=ajhwb@knac.com \
    --cc=canaan.kao@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).