I have a file transfer code written in C using windows sockets which seems to work but keeps transferring fewer than the desired number of bytes of the file.
Any ideas?
Send code:
while(!feof(fp))
{
bzero(bufferin,256);
fread(bufferin,sizeof(char),255,fp);
send(remsock,bufferin,255,0);
if(n < 0)
error("ERROR writing to socket");
}
send(remsock,"done",255,0);
Accept code:
while(1)
{
recv(sockfd,buffer,255,0);
if(compare(buffer,"done") == 0)
break;
fwrite(buffer,1,255,fplog);
}
printf("File Transfer complete\n\n");
As others have stated, you MUST look at the return values of all the functions you are calling, eg:
Sending:
Receiving: