title: UDP with multiple sender and one single receiver
body: <p>In a project I have multiple senders of UDP data, but only a single receiver.</p>
  
  <p>If traffic gets higher, the receiver "forgets" lots of packets. I know that this is a problem inherent to UDP, but I want to minimize the number of lost packets.</p>
  
  <p>I have read <a href="https://stackoverflow.com/questions/10832770/sending-udp-broadcast-receiving-multiple-messages">this</a> SO question before!</p>
  
  <p>Here is my code (Please excuse the massive code blocks, but I wanted the example to be self contained)</p>
  
  <p><strong>Sender side:</strong></p>
  
  <pre><code>public class UdpSender
  {
      private static int portNumber = 15000;
  
      public void Send(string data)
      {
          var udpServer = new UdpClient();
          var ipEndPoint = new IPEndPoint(IPAddress.Broadcast, portNumber);
          byte[] bytes = Encoding.ASCII.GetBytes(data);
          udpServer.Send(bytes, bytes.Length, ipEndPoint);
          udpServer.Close();
      }
  }
  
  
  class Program
  {
      static void Main(string[] args)
      {
          var sender = new UdpSender();
          var count = 100000;
  
          for (var i = 0; i &lt; count; ++i)
          {
              sender.Send(i.ToString());
          }
  
          Console.ReadKey();
      }
  }
  </code></pre>
  
  <p><strong>Receiver side:</strong></p>
  
  <pre><code>public class UDPListener
  {
      private static int portNumber = 15000;
      private readonly UdpClient udp = new UdpClient(portNumber);
  
      public volatile int CountOfReceived = 0;
  
      public void StartListening()
      {
          this.udp.BeginReceive(Receive, new object());
      }
  
      private void Receive(IAsyncResult ar)
      {
          Interlocked.Increment(ref CountOfReceived);
  
          IPEndPoint ip = new IPEndPoint(IPAddress.Any, portNumber);
          byte[] bytes = udp.EndReceive(ar, ref ip);
          string message = Encoding.ASCII.GetString(bytes);
          StartListening();
      }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          var listener = new UDPListener();
  
          listener.StartListening();
  
          while (true)
          {
              Console.WriteLine(listener.CountOfReceived.ToString("000,000,000"));
          }
  
      }
  }
  </code></pre>
  
  <p>Right now if I start 5 sender applications in parallel, only about a quarter of the messages is received. This is only on my local machine.</p>
  
  <p><strong>What can I do to minimize packets lost?</strong></p>