title: File transmission over TCP with Python
body: <p>I'm currently working on a python project, that requires file transmission from a client to a server via the Python socket.
  Here is my current code, that however doesn't transmit the whole file, but there are always some bites missing, or additional bytes, according to the file sizes.</p>
  
  <p>_con and con are connection wrappers connections via the python socket.</p>
  
  <p>Client:</p>
  
  <pre><code>def _sendFile(self, path):
      sendfile = open(path, 'rb')
      data = sendfile.read()
  
      self._con.sendall(data)
  
      self._con.send(bytes('FIN', 'utf8'))
      # Get Acknowledgement
      self._con.recv(6)
  
  def _recieveFile(self, path):
      # Recieve the file from the client
      writefile = open(path, 'wb')
      i = 0
      while (1):
          rec = self.con.recv(1024)
          if (rec.endswith(b'FIN')):
              break
          writefile.write(rec)
  
      self.con.send(b'ACK')
  </code></pre>