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):
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( read(ns, buf, BUFSIZE) ){ //printf("%s\n", buf); fwrite(buf,sizeof(char),BUFSIZE,fp); }
I should say that in this part of code the server's read() waits for the client's write().Code:while(fread(buf,sizeof(char),BUFSIZE,fp)!=0){ write(sockfd, buf, BUFSIZE); //printf("%s\n", buf); }
The problem is when i try to pass a file like this: (example.txt)
i have as a result:Code:FILE FROM THE CLIENT FILE FROM THE CLIENT FILE FROM THE CLIENT
And i suspect fwrite() function in the server needs something more.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
Help please and thanks in advance



LinkBack URL
About LinkBacks



, such a mistake.