How large should my recv buffer be when calling recv in the socket library

Posted by Silmaril89 on Stack Overflow See other posts from Stack Overflow or by Silmaril89
Published on 2010-05-19T00:19:47Z Indexed on 2010/05/19 0:30 UTC
Read the original article Hit count: 505

Filed under:
|

Hi, I have a few questions about the socket library in C. Here is a snippet of code I'll refer to in my questions.


char recv_buffer[3000];
recv(socket, recv_buffer, 3000, 0);

First, How do I decide how big to make recv_buffer? I'm using 3000, but it's arbitrary. Second, what happens if recv() receives a packet bigger than my recv_buffer? Third, how can I know if I have received the entire message without calling recv again and have it wait forever when there is nothing to be received?

And finally, is there a way I can make a buffer not have a fixed amount of space, so that I can keep adding to it without fear of running out of space? maybe using strcat to concatenate the latest recv() response to the buffer?

I know it's a lot of questions in one, but I would greatly appreciate any responses.

© Stack Overflow or respective owner

Related posts about socket

Related posts about c