title: OnMessage() functionality for UDP
body: <p>I was wondering if there is a type of OnMessage() type functionality for UDP messages using DatagramPacket? I want to be able to ensure that I get all messages when they come across so I don't waste resources randomly grabbing on a timer.</p>
  
  <p>The OnMessage I am referring to the one done in WebSocketClient. Or some functionality similar to "Available" in .net.</p>
  
  <pre><code>While (rxUdpClient.Available &gt; 0)
  </code></pre>
  
  <p>I am monitoring several ports so a thread is called which will do a run() for each port. Problem is I seem to have messages coming in at a massive rate 40+/sec.</p>
  
  <p>This is what I currently have:</p>
  
  <pre><code>public void run()
  {
      DatagramSocket sock = null;       
          sock = new DatagramSocket(port);
      byte[] buffer = new byte[DataAdapterFB1.HEADER_SIZE + DataAdapterFB1.MAX_DATA_BYTES];
      DatagramPacket incoming = new DatagramPacket(buffer, buffer.length);
  
      while (true){           
          sock.receive(incoming);           
          byte[] data = incoming.getData();
          String s = new String(data, 0, incoming.getLength());
          //This is the processing code, but it isn't its own thread...
          ScadaMsg newMessage = new ScadaMsg(data);
       }
  }
  </code></pre>