title: Sending data over UDP to a destination with multiple clients open
body: <p>I am currently using this function to send data from the server to the clients</p>
  
  <pre><code>private static void send_message(string ip, string message)
  {
      byte[] packetData = System.Text.UTF8Encoding.UTF8.GetBytes(message);
  
      int port = 11000;
  
      IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ip), port);
      Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
      client.SendTo(packetData, ep);
  }
  </code></pre>
  
  <p>But this would mean a destination IP/port can only have one client open to receive the data, because having two clients open would mean one client can retrieve data that was meant for another (if I'm correct).. how do I solve this?</p>
  
  <p>Receiving function:</p>
  
  <pre><code>private static Int32 port = 11000;
  private static UdpClient udpClient = new UdpClient(port);
  
  public static void receive_threaded()
  {
      Thread t = new Thread(() =&gt;
      {
          while (true)
          {
              IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Any, port);
              byte[] content = udpClient.Receive(ref remoteIPEndPoint);
  
              if (content.Length &gt; 0)
              {
                  string message = Encoding.UTF8.GetString(content);
                  parseMessage(message);
              }
          }
      });
      t.Start();
  }
  </code></pre>