Re: recv() - How do you know the length of buffer that you are going to receive?
- From: "Nils O. Selåsdal" <NOS@xxxxxxx>
- Date: Mon, 19 Dec 2005 10:48:11 +0100
Steven wrote:
Hi everyone,
I'm puzzled. How do you usually define the length to be given for recv()? Since you do not know what is the length of the buffer you are going to receive?
You must have an application protocol. It could be as simple as "read everything until the stream is closed", in which case you divide it up in suitable chunks and grow up a buffer in memory, or write to a file as you go. Or, you could send the length of each part/message/etc. first, as e.g. 4 octets. Then you can read 4 octets which represent the length of the data that is about to come.
Remember, if you're using TCP, it's a stream write bundaries at one end of the connection are NOT preserved. You can't know how much data the other end sent using just one write/send call, and TCP can split/merge those at will. .
- Follow-Ups:
- References:
- Prev by Date: Re: recv() - How do you know the length of buffer that you are going to receive?
- Next by Date: Re: what happen to heap on programme exit
- Previous by thread: Re: recv() - How do you know the length of buffer that you are going to receive?
- Next by thread: Re: recv() - How do you know the length of buffer that you are going to receive?
- Index(es):
Relevant Pages
|