title: Strengthen python UDP server
body: <p>I'm a beginner in python (2.6/2.7) who has been thrown in the deep end to create a network service to an existing python app.</p>
  
  <p>I've got a UDP server up and running which works just great but I'm asking for help in making it slightly more bullet proof.</p>
  
  <p>Here is the base code I have written, the usual standard boiler plate:</p>
  
  <pre><code>import sys
  import socket
  from threading import Thread
  
  def handleInput():
           sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
           sock.bind( ("127.0.0.1",5005) )
           # socket always binded?
           while True:
                   data, addr = sock.recvfrom(512)
                   # is 'data' usable?
  
  t=Thread(target=handleInput)
  t.daemon=True
  t.start()
  # can thread die?
  </code></pre>
  
  <p>Firstly, I understand that the socket is in a sense always available, it doesn't have to listen, so there is no such thing as failing and you have to reconnect. Is this correct?</p>
  
  <p>Secondly, the issue with returned data from recvfrom. Is it a simple  <strong>'if data : then'</strong> to check if its valid?</p>
  
  <p>Thirdly, and finally, the thread. Can a thread bomb out? If it does whats the best way to restart it?</p>
  
  <p>Any other tips would be welcome.</p>
  
  <p>(Note: I cannot use external libraries, e.g. twisted etc.)</p>