[ back to toc ]

send() call in C merging

Date: 2002/03/14 10:23

Hi, I am currently writing a server deamon on a machine running slackware
linux 8. This server is connecting to a windows based client that I am
also writing using winsock under visual c++ 6. I am fork()'ing off each
connection to a new process, which calls a handling function. However I
am finding that when successive send() calls are made on the server side,
the TCP stack on either machine (dunno which one) is joining what I intend
to be 3 seperate successive transmittions into 1 larger transmittion which
is retreived using 1 blocking recv() call, and this is causing difficulty
and requiring unnessesary complexity on the client side of the program to

The following function on the server machine is used to send the data:

void sendstream(SOCKET connsock, char dataBuff[255]){
int nRet;
nRet = send(connsock, dataBuff, strlen(dataBuff), 0);
if (nRet == SOCKET_ERROR) {
printf("DEBUG:Error on send()");

How do you reccommend I get around this problem? Is it possible to ensure
that the send() call will send its data when it is called, and not join
the data send by successive calls?

Thanks for any help you can offer.

I have not faced such aproblem in my practice. I developed an HTTP server,
which was not keep on talking back and forth and thus received all data
and then sent all data. I copy here the send function and receive function
that I used:

static int _WriteClient(pThreadData ThisThread,
char *pszBuffer,
int cbBuffer){
int i;
fd_set writefds;
struct timeval timeout;

i = select(FD_SETSIZE,NULL,&writefds,NULL,&timeout);
if( i == 0 )return 1;
return cbBuffer != send(ThisThread->msgsock,pszBuffer,cbBuffer,0);

static int _ReadClient(pThreadData ThisThread,
char *pszBuffer,
int cbBuffer){
int i;
fd_set readfds;
struct timeval timeout;

i = select(FD_SETSIZE,&readfds,NULL,NULL,&timeout);
if( i == 0 )return 0;

return recv(ThisThread->msgsock,pszBuffer,cbBuffer,0);

this may help.


[ back to toc ]