title: Python file transfer completes only after Control-C
body: <p>I am trying the multithreaded python program to connect to server by multiple clients at the same time. The program runs successfully but the image I am trying to send has incomplete data until I terminate the program using Control C. After Control-C, the file reloads and complete image is visible.
  I am posting my code here :
  Server.py</p>
  
  <pre><code>from socket import *
  import thread
  
  def handler(clientsocket, clientaddr):
      print "Accepted connection from: ", clientaddr
  
      while 1:
          data = clientsocket.recv(8192)
          if not data:
              break
          else:
              print "The following data was received - ",data
              print "Opening file - ",data
              fp = open(data,'r')
              strng = "hi"
              while strng:
                  strng = fp.read(8192)
                  clientsocket.send (strng)
  
  
      clientsocket.close()
  
  if __name__ == "__main__":
  
      host = 'localhost'
      port = 55574
      buf = 8192
  
      addr = (host, port)
  
      serversocket = socket(AF_INET, SOCK_STREAM)
  
      serversocket.bind(addr)
  
      serversocket.listen(5)
  
      while 1:
          print "Server is listening for connections\n"
  
          clientsocket, clientaddr = serversocket.accept()
          thread.start_new_thread(handler, (clientsocket, clientaddr))
      serversocket.close()
  </code></pre>
  
  <p>Client.py :</p>
  
  <pre><code>from socket import *
  import os
  if __name__ == '__main__':
  
      host = 'localhost'
      port = 55574
      buf = 8192
  
      addr = (host, port)
  
      clientsocket = socket(AF_INET, SOCK_STREAM)
  
      clientsocket.connect(addr)
  
      while 1:
          fname = raw_input("Enter the file name that u want&gt;&gt; ")
          if not fname:
              break
          else:
              clientsocket.send(fname)
              print "\nThe file will be saved and opened- "
              fname = '/home/coep/Downloads/'+fname
              nf = open(fname,"a")
              strng = "hi"
              while strng:
                  strng = clientsocket.recv(8192)
                  nf.write(strng)
  
              nf.close()
              fname = 'viewnior '+ fname
              print fname
              os.system(fname)
  </code></pre>