title: C# UDP protocol image sending
body: <p>I simply try to send a screen shot using Udp protocol this is the code:</p>
  <pre><code>  private void Form1_Load(object sender, EventArgs e)
      {
  
          Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
         ProtocolType.Udp);
  
          IPAddress broadcast = IPAddress.Parse(&quot;10.0.0.4&quot;);
  
          Bitmap bitmap=GetDesktopImage();//generate screenshot.
          byte[] sendbuf = imageToByteArray(bitmap);
          IPEndPoint ep = new IPEndPoint(broadcast, 10);
  
          s.SendTo(sendbuf, ep);
  
          Console.WriteLine(&quot;Message sent to the broadcast address&quot;);
  
      }
  </code></pre>
  <p>ImageToByteArray is a function which converts the image into a byte array you can see <a href="http://www.codeproject.com/Articles/15460/C-Image-to-Byte-Array-and-Byte-Array-to-Image-Conv" rel="nofollow noreferrer">here</a>.</p>
  <p>However im getting an odd exception when the <code>s.SendTo()</code> line is executed with the following error details:</p>
  <blockquote>
  <p>A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself</p>
  </blockquote>
  <p>Im not sure but i think it's related to the size of the data sent..
  Any help?</p>