Socket programming simple question:
hi
I am a newbie to socket programming. I am trying to transfer a file from one computer to other using TCP sockets.... I have explained my problem below.
there are two programs, talker and listener. The talker side establishes the connection (has connect() function) and listener had bind(), listen() and accept() functions.
I am transmitting a file from talker to listener. I run the listener first and then the talker.
My problem is, how to make the listener detect that all the contents of the file have been received. The listener is running first. It receives the file when sent and then continues to listen rather than ending the program.
Breifly, the problem is "how to break from this loop? "..right now, I use
while (totalbytes < BYTESTORECEIVE)
{
numbytes = recv ( sockfd, buf, MAXBUFLEN, 0); // buf is char*
fputs(buf,outfile);
totalbytes += numbytes;
}
but I WOULD NOT know the BYTESTORECEIVE always. I tried while(buf == EOF) and (numbytes != 0) but they still remain in loop. One can use EOF with character but with a string ?
What should I do.
Thanks for your time.
Ash
|