title: sending/receiving file UDP in python
body: <p>I've made this sending / receiving scripts but i corrupted file !
  i have no idea why I'm getting this issue !</p>
  
  <p>sender.py</p>
  
  <pre><code>#!/usr/bin/env python
  
  from socket import *
  import sys
  
  s = socket(AF_INET,SOCK_DGRAM)
  host =sys.argv[1]
  port = 9999
  buf =1024
  addr = (host,port)
  
  file_name=sys.argv[2]
  
  f=open(file_name,"rb") 
  data = f.read(buf)
  
  s.sendto(file_name,addr)
  s.sendto(data,addr)
  while (data):
      if(s.sendto(data,addr)):
          print "sending ..."
          data = f.read(buf)
  s.close()
  f.close()
  </code></pre>
  
  <p>receiver.py</p>
  
  <pre><code>#!/usr/bin/env python
  
  from socket import *
  import sys
  import select
  
  host="0.0.0.0"
  port = 9999
  s = socket(AF_INET,SOCK_DGRAM)
  s.bind((host,port))
  
  addr = (host,port)
  buf=1024
  
  data,addr = s.recvfrom(buf)
  print "Received File:",data.strip()
  f = open(data.strip(),'wb')
  
  data,addr = s.recvfrom(buf)
  try:
      while(data):
          f.write(data)
          s.settimeout(2)
          data,addr = s.recvfrom(buf)
  except timeout:
      f.close()
      s.close()
      print "File Downloaded"
  </code></pre>
  
  <p>and this the original receiver that I've modify it (works fine 100%)</p>
  
  <pre><code>#!/usr/bin/env python
  
  from socket import *
  import sys
  import select
  
  host="0.0.0.0"
  port = 9999
  s = socket(AF_INET,SOCK_DGRAM)
  s.bind((host,port))
  
  addr = (host,port)
  buf=1024
  
  f = open("file.pdf",'wb')
  
  data,addr = s.recvfrom(buf)
  try:
      while(data):
          f.write(data)
          s.settimeout(2)
          data,addr = s.recvfrom(buf)
  except timeout:
      f.close()
      s.close()
      print "File Donwloaded"
  </code></pre>
  
  <p>as you notice it's making file at the beginning.</p>
  
  <p>exacted: 
  client  => send file (name.ext) => server:save it (name.ext)</p>
  
  <p>my output :
  corrupted file for pdf and empty for txt  </p>