Hello everyone.
I am trying to write a server-client program (INET)
I have all the connections ok but i have on e problem. When i try to pass binary data from the client to the server I dont know how to recognize whether I reached the EOF.
in my code:
ns is the file descriptor generated by accept() system call.
BUFSIZE is 256
buf is declared as char buf[BUFSIZE]
and fp is my FILE pointer. (the one I want to write.)
SERVER CODE(one part):
Code:
while( read(ns, buf, BUFSIZE) ){
//printf("%s\n", buf);
fwrite(buf,sizeof(char),BUFSIZE,fp);
}
In the client buf and BUFSIZE are similar to the ones declared in the server. fp is the FILE pointer to the file i am trying to read. sockfd is the file descriptor generated by socket() system call. and the code is:
Code:
while(fread(buf,sizeof(char),BUFSIZE,fp)!=0){
write(sockfd, buf, BUFSIZE);
//printf("%s\n", buf);
}
I should say that in this part of code the server's read() waits for the client's write().
The problem is when i try to pass a file like this: (example.txt)
Code:
FILE FROM THE CLIENT
FILE FROM THE CLIENT
FILE FROM THE CLIENT
i have as a result:
Code:
FILE FROM THE CLIENT
FILE FROM THE CLIENT
FILE FROM THE CLIENT????????m??c???t??t??`???Z?????????????????0`H?Z?Z?????????|?????????????`????1?#0?m???????????h??????m?????funcs
And i suspect fwrite() function in the server needs something more.
Help please and thanks in advance