|
From: michal.shmueli on 8 Jan 2006 23:41 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's stuck forever... 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.
From: David Schwartz on 9 Jan 2006 00:33 <michal.shmueli(a)gmail.com> wrote in message news:1136666411.601574.164620(a)o13g2000cwo.googlegroups.com... > 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. When you have all the data, don't call 'recv' again. Your code keeps calling it. Only call 'recv' when you know the other end is going to send you data. DS
|
Pages: 1 Prev: Failing NFS, Internet, and more Next: telnet syntax for ports |