title: Delay when receiving UDP packets in Python in real-time
body: <p>I am using <a href="https://github.com/opentrack/opentrack" rel="nofollow">Opentrack</a> to track head movements and the coordinates are sent through UDP to my Python program. The program works in the sense that it receives the coordinates correctly, but however I have noticed that there is a large delay before information arrives. </p>
  
  <p>After observing the behaviour it seems to me that the tracking software sends the coordinates to some buffer that my program fetches the data from, but my program is slower to fetch the data than the speed which the buffer fills up. This means that if I move my head then those new coordinates have all been detected but the program has to gradually go through the buffer which causes the delay. This is a problem since I am using this as a real-time application that needs to send the current coordinates instantly to my program all the time.</p>
  
  <p>I'm not sure if the problem is in the Opentrack software and if I should head over to that community for help, or if I can fix it in Python...</p>
  
  <p>Basically, I just wish there wasn't a buffer but that it instead just sent the current coordinates (it doesn't matter if some measured coordinates are lost in my application). </p>
  
  <pre><code>def connect(self, PORT):
      HOST = ''   # Symbolic name meaning all available interfaces
      #PORT = 8888 # Arbitrary non-privileged port
  
      # Datagram (udp) socket
      try :
          self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
          print 'Socket created'
      except socket.error, msg :
          print 'Failed to create socket. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
          sys.exit()
  
  
      # Bind socket to local host and port
      try:
          self.s.bind((HOST, PORT))
      except socket.error , msg:
          print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
          sys.exit()
  
      print 'Socket bind complete'
  
  #now keep talking with the client
  def fetch(self):
      # receive data from client (data, addr)
      d = self.s.recvfrom(1024)
      data = d[0]
      addr = d[1]
  
      if data: 
  
          reply = 'OK...' + data
  
          self.s.sendto(reply , addr)
  
          unpacked_data = struct.unpack('dddddd', data)
          x = unpacked_data[0]
          y = unpacked_data[1]
          z = unpacked_data[2]
          return (x, y, z)
  </code></pre>