> Any clue why?
Well posting the message logs of both client and server would have been a big help.
First off, having a 300 line main is horrible.
Split the whole thing into functions which
- parse arguments
- handle the whole client
- handle the whole server
Client and server need to be further broken down into
- create the connection
- handle the file transfer
- close the connection
2. A whole bunch of variables which are declared float should be integral types.
Convert to float WHEN you need to do the maths, not before.
Code:
unsigned char buff[256] = {0};
float nread = fread(buff, 1, sendSize, fp);
3. Lying about your buffer sizes is a sure way to mess things up.
Besides, the entire loop is a waste of code. The other file read loop will do the job just perfectly. You've already done fseek(fp, sendSize, SEEK_SET);
Code:
FILE *fp;
float total = 0;
float bytesReceived = 0;
char buff[256];
memset(buff, '0', sizeof(buff));
float percentage = (total / bytesReceived) * 100;
while ((bytesReceived = read(msgSock, buff, 256)) > 0) {
fwrite(buff, sizeof(char), sizeof(buff), fp);
printf("\r%s: Percentage received: %.2f", NAME_C, percentage);
}
1. You didn't open the file.
2. the memset is a waste of time, you're going to overwrite the buffer anyway.
3. the fwrite should use bytesReceived and not sizeof(buff).
> if (returnValue = WSAStartup(0x202, &wsaData) != 0)
You need to have explicit parentheses here. You've written this.
if (returnValue = (WSAStartup(0x202, &wsaData) != 0))
> printf("%s: Accepted connection from %s", inet_ntoa(outsideSock.sin_addr));
This is missing an argument for the second %s