title: Split to fit packets c# UDP
body: <p>How can i split a packet into smaller parts, and then send it?
  Currently i have tried doing it very manually, for example an image.</p>
  
  <p>I would have 2 udp clients, have an image that´s, let´s say 800x600.
  Send 1 udp client with 800x300 and the other 800x300.</p>
  
  <p>Then merge them.</p>
  
  <p>But i am thinking there must be a better way, some kind of function to to this?
  As it becomes extremely hard with big packages, i will have to make like 10+ udpclients.</p>
  
  <pre><code>    private void Initialize()
      { 
  
  
          Bitmap holder = new Bitmap(640, 480);
  
          pictureBox1.Size = new System.Drawing.Size(1920, 1200);
          EndPoint ourEP = new IPEndPoint(IPAddress.Any, 0);
  
          EndPoint remoteEP = (EndPoint)(new IPEndPoint(IPAddress.Any, 1700));
          EndPoint remoteEP2 = (EndPoint)(new IPEndPoint(IPAddress.Any, 1701));
  
  
          udpcap = new UdpClient();
          udpcap1 = new UdpClient();
          udpcap.Client.Bind(remoteEP);
          udpcap1.Client.Bind(remoteEP2);
  
       }
  
  
   private void Listen()
      {
          while (checkBox1.Checked)
          {
              byte[] data = udpcap.Receive(ref adress);
              byte[] data2 = udpcap1.Receive(ref adress);
              Bitmap bitmap = new Bitmap(byteArrayToImage(data).Width + byteArrayToImage(data2).Width, Math.Max(byteArrayToImage(data).Height, byteArrayToImage(data2).Height));
              using (Graphics g = Graphics.FromImage(bitmap))
              {
                  g.DrawImage(byteArrayToImage(data), 0, 0);
                  g.DrawImage(byteArrayToImage(data2), byteArrayToImage(data).Width, 0);
              }
  
              pictureBox1.BackgroundImage = bitmap;
  
          }
      }
      private static Image cropImage(Image img, Rectangle cropArea)
      {
          Bitmap bmpImage = new Bitmap(img);
          Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
          return (Image)(bmpCrop);
      }
      private void Send()
      {
          bool p = true;
          while (capcon == true)
          {
              Rectangle h = new Rectangle(0, 0, 320, 480);
              Bitmap holder = new Bitmap(640, 480);
              Graphics graphics = Graphics.FromImage(holder);
              graphics.CopyFromScreen(0, 0, 0, 0, new Size(1920, 1200), CopyPixelOperation.SourceCopy);
  
              byte[] u = imageToByteArray(cropImage(holder, h));
              udpcap.Send(u, u.Length, adress.Address.ToString(), 1700);
              h = new Rectangle(320, 0, 320, 480);
              byte[] u1 = imageToByteArray(cropImage(holder, h));
              udpcap1.Send(u1, u1.Length, adress.Address.ToString(), 1701);
  
          }
      }
  </code></pre>
  
  <p>Here is the code, what it´s doing is simple.
  Take a screenshot of the desktop.
  place it in 640x480 bitmap (much less then the desktop size though).</p>
  
  <p>Send 2 packages with 2 halves of the picture.</p>
  
  <p>Recieve the data, combine them, and place them as a background.</p>
  
  <p>Now, this works for 640x480, which is very small.</p>
  
  <p>Now if i want to do it with something higher, i must make extremely many packages.
  So i wonder if it is possible to have it a bit more, automatic.</p>
  
  <p>Why i am splitting packages and using many clients is cause i don´t know how to send something bigger than the buffer (65kb), tried searching on it, but i don´t understand.</p>