recv() problem?- need help

This is a discussion on recv() problem?- need help within the Linux Networking forums, part of the Linux Forums category; Hi, I'm kind of new for networking programming and need to write some basic socket connection (in C) using ...


Go Back   Usenet Forums > Linux Forums > Linux Networking

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-08-2006
michal.shmueli@gmail.com
 
Posts: n/a
Default recv() problem?- need help

Hi,
I'm kind of new for networking programming and need to write some
basic socket connection (in C) using 2 linux machines that do the
following:
The client sends request (query) to the server, then the server needs
to send the query results to the client. So I established the
connection, and the client seems to get the query correctly and send
the results back to the client. The only problem is that the client is
either getting part of the data- when I'm using:
/*********************************************
RECEIVES THE OUTPUT FROM THE SERVER
**********************************************/
strcpy(buf, "");
if ((numbytes=recv(sockfd, buf, MAX-1, 0)) == -1) {
error("recv");
exit(1);
}
buf[numbytes] = '\0';
printf("%s",buf);

or when I'm trying to use a while loop it got stuck forever...:

/*********************************************
RECEIVES THE OUTPUT FROM THE SERVER - loop
**********************************************/
strcpy(buf, "");
while(recv(sockfd, buf, MAX-1, 0) >0) {
printf("%s",buf);
}


as for the server, I'm using:
/**********************************
SENDS THE OUPUT
***********************************/
if (send(new_fd, rdata1, MAX, 0) == -1){
//error
}
close(new_fd);
exit(0);

what is wrong with this? How can I terminate the recv() in such a way
that it should stop after getting all the data back? Any help will be
appreciated.

Thanks.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:00 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0