Hi all. Thanks ahead for reading this, heres the background
I've been trying to make a simple peer-to-peer and I'm stuck at the very last part of this. Now don't get me wrong, I'm in 3rd year univ, and we've been working on this for 3 days, about 8 hrs each day (Just the part I'm about to explain now) and the teacher assitant can't help either.
::: (coding in linux)
Code:
void processFile(char *file,int peerfd){
char buf[1];
int fd;
printf("Filename is %s\n",file);
if ((fd=open(file,O_RDONLY)) ==-1){
fprintf(stdout,"Usage Error: File does not exist\n");
exit(1);
}
else{
while(read(fd,buf,sizeof(buf))!=0){
write(peerfd,buf,sizeof(buf));
printf("r");
}
close(fd);
}
Where peerfd is the file descripter that is made , connected to the other peer. The problem is, once we run it and send a file (file exists etc) , hit hangs, so we hit cntrl-c to terminate it, and only then it displays on the peer window (file received). So we fix this by typing close(peerfd), but doing this makes pictures send fine, but txt files only get sent 1byte (notice the size of buff)
Edit:
I talked to the TA, it seems that the peer is expecting some symbol, or some flag that says "OK the file is finished sending". See I'm testing this against a client that I know works, but we're not aloud to look at it . So when I close the file descriptor myself, by saying close (fdpeer), it gives me
read from peer: Connection reset by peer
Which means the peer is still expecting data (even though I finished sending) and its what I would call a brutal disconnection.
Thanks!!!