title: Socket lose part of message in UDP
body: <p>I am trying to send an image frame through a UDP socket with Python 2.7, the current frame I am trying to send is <code>921600</code> bytes <code>(640 x 480)</code>. And the buffer limit for UDP messages are <code>65507</code> bytes, so I need to split the message, here is how I am doing it.</p>
  
  <p>From <code>client.py</code>:</p>
  
  <pre><code>image_string = frame.tostring()              # frame is an multi-d numpy array
  message_size = len(image_string)
  sock.sendto(str(message_size), (HOST, PORT)) # First send the size
  
  for i in xrange(0, message_size, 65507):     # Split it and send
      sock.sendto(image_string[i:i + 65507], (HOST, PORT))
  
  sock.sendto("\n", (HOST, PORT))              # Mark the end to avoid hanging.
  </code></pre>
  
  <p>Here is how I am receiving it in <code>server.py</code>, I inserted some prints for debugging.</p>
  
  <pre><code>image_string = ""
  
  data, addr = sock.recvfrom(1024) # recieve image size
  message_size = int(data)
  print "Incoming image with size: " + data
  
  for i in xrange(0, message_size, 65507):
      data, addr = sock.recvfrom(65507)
      image_string += data.strip()
      print "received part, image is now:", len(image_string)
  
  print "End of image"
  </code></pre>
  
  <p>So I am reading the message same way I send it, it checks out in theory however not in practice.  Possibly because of some packet loss after the client is done sending - the <strong>server is still stuck trying to read</strong> (blocked).</p>
  
  <p>I know that UDP is unreliable and hard to work with, however I read that UDP is used in many video streaming applications, so I believe there should exist a solution to this problem, but I can not find it.</p>
  
  <p>All help is appreciated, thanks.</p>
  
  <p><strong>Edit1:</strong> The reason I suspect packet loss is the problem, is because every time I run the test, I end up with different size of image being already sent before the server hangs.</p>
  
  <p><strong>Edit2:</strong> I forgot to mention that I tried different size of chunks while partitioning, 1024 and 500 bytes revealed no difference (5-20 bytes lost in 921600). But I should mention that I am sending and recieving from localhost, which already provides minimum error.</p>