This is a discussion on recv() problem? 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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|