Last active
August 29, 2015 14:17
-
-
Save vik-y/ef305b179cbfc08e0c99 to your computer and use it in GitHub Desktop.
Send a file - c socket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Works perfectly with the send written above | |
char recvBuff[10]; | |
int bytesReceived = recv(new_fd, recvBuff, 10, 0); | |
while(bytesReceived != 0) | |
{ | |
// you should add error checking here | |
fwrite(recvBuff, bytesReceived, 1, outputFile); | |
bytesReceived = recv(new_fd, recvBuff, 10, 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILE *inputFile = fopen("testfile.txt", "r"); | |
char sendBuffer[20]; | |
// TODO: Check for errors here | |
int bytesRead = fread(sendBuffer, 1, 10, inputFile); //Reading 10 byte at a time | |
//10 values of 1 byte each | |
while(!feof(inputFile)) | |
{ | |
//TODO: check for errors here | |
send(sockfd, sendBuffer, bytesRead, 0); | |
printf("%s %d ", sendBuffer, bytesRead); | |
bytesRead = fread(sendBuffer, 1, 10, inputFile); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment