send_content.cpp 544 B

12345678910111213141516171819202122232425262728293031
  1. #include "stdafx.h"
  2. #include <winsock2.h>
  3. #include "constdef.h"
  4. bool sendContent(SOCKET s, char* filePath)
  5. {
  6. char buf[MAXSIZE] = {'\0'};
  7. FILE* filePtr;
  8. fopen_s(&filePtr, filePath, "rb");
  9. if(filePtr == NULL)
  10. {
  11. //printf("Failed to open the file\n");
  12. return false;
  13. }
  14. else
  15. {
  16. int sendCount;
  17. while(!feof(filePtr))
  18. {
  19. sendCount = fread(buf,sizeof(char), MAXSIZE, filePtr);
  20. send(s, buf, sendCount, 0);
  21. if(ferror(filePtr))
  22. {
  23. //printf("File read error\n");
  24. return false;
  25. }
  26. }
  27. }
  28. fclose(filePtr);
  29. return true;
  30. }