title: UDP Message too long
body: <p>I'm trying to send data over UDP and wondering why the maximum data length is limited to 9253 bytes on my system (Mac OS X 10.9).</p>
  
  <p>This is how I send data (simplified):</p>
  
  <pre><code>import socket
  
  UDP_IP = "127.0.0.1"
  UDP_PORT = 9999
  MESSAGE = "A"*9217
  
  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
  </code></pre>
  
  <p>and I got the error</p>
  
  <pre><code>Traceback (most recent call last):
    File "Untitled 2.py", line 8, in &lt;module&gt;
      sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
  socket.error: [Errno 40] Message too long
  </code></pre>
  
  <p>In fact, the maximum "string length" I can transfer is 9216. When I do a byte size check on the client side via</p>
  
  <pre><code>import socket
  
  UDP_IP = "127.0.0.1"
  UDP_PORT = 9999
  
  self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  self.sock.bind((UDP_IP, UDP_PORT))
  data, addr = self.sock.recvfrom(65535)
  print("Received {0} bytes of data.".format(sys.getsizeof(data)))
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>Received 9253 bytes of data.
  </code></pre>
  
  <p>I don't understand why it is 9253 bytes long, when I send 9216 bytes (this is the string length in bytes). 28 bytes is the UDP header but what is stored in the remaining 9 bytes?</p>
  
  <p>And my main problem: how do I send and receive UDP packets up to 65535 bytes?</p>