title: I am getting some garbage value while sending file data through socket to server? Why?
body: <p>I am setting up a client server connection through sockets in C++. I am successfully connecting them but while sending filesize  and file data i am receiving some garbage values also in my server.</p>
  
  <p>I am firstly sending File Size through send system call from client and then sending file Buffer to server.</p>
  
  <p>I have recv system call in server which is successfully receiving Filesize, but while getting File data after some bytes i am getting garbage.</p>
  
  <p>Client Code</p>
  
  <pre><code>File = fopen("index.jpg", "rb");
  if (!File)
  {
      MessageBox(L"Error while readaing the file");
  
  }
  fseek(File, 0, SEEK_END);
  Size = ftell(File);
  fseek(File, 0, SEEK_SET);
  
  char* Buffer = new char[Size];
  
  fread(Buffer, Size, 1, File);
  
  
  
  char cSize[MAX_PATH];
  sprintf(cSize, "%lu", Size);
  
  
  
  send(Socket, cSize, MAX_PATH, 0); // File size
  send(Socket, Buffer, Size, 0); // File Binary
  </code></pre>
  
  <p>Server Code</p>
  
  <pre><code>          unsigned long Size;
      char *Filesize = new char[1024];
  
      if (recv(Sub, Filesize, 1024, 0)) // File size
      {
         Size = strtoul(Filesize, NULL, 0);  //getting filesize
      }
  
  
      Buffer = new char[Size];
      int reader = recv(Sub, Buffer, Size, 0);
      Buffer[Size] = '\0';
      if (reader == -1) // File Binary
      {
          MessageBox(L"Perror Recv");
      }
      else if (reader == 0)
      {
          MessageBox(L"Connection is Closed");
      }
      else
      {
          FILE *File;
          File = fopen("test.jpg", "wb");
          fwrite((const char*)Buffer, 1, Size, File);  
          MessageBox(L"DATA Received");
          fclose(File);
      }
  </code></pre>