title: Arduino: UDP sending yields extra characters
body: <p>At the moment I have an Arduino board with an Ethernet Shield connected to a router. My computer connects to this router via Wi-Fi. My board and my computer send <a href="http://en.wikipedia.org/wiki/User_Datagram_Protocol" rel="nofollow">UDP</a> messages back and forth to each other. My computer is a client, and the board is a server. However I noticed, that when I send a longer UDP message from my computer, and then a shorter UDP message, the Arduino accepts the shorter message, then followed by remaining bits from the longer message.</p>
  
  <p>For instance: if I send "Hello World" from my computer, followed with "Test"; the Arduino will not read the second message as "Test", but rather: "Testo World".</p>
  
  <p>I thought perhaps in was a problem from the Arduino end first. The Arduino stores the messages temporarily in an array called <code>packetBuffer</code>. I tried clearing this buffer before I receive a new message each time. The buffer would clear, but then I would receive the faulty message again.</p>
  
  <p>So I assume the culprit is the computer, the client. On the computer end I have a processing sketch that sends the UDP messages. The example below is not the sketch itself; however it is by far a simpler example that still provides the exact symptoms as I described with my original sketch.</p>
  
  <pre><code>import hypermedia.net.*;
  
  UDP udp;  // define the UDP object
  
  
  void setup() {
      udp = new UDP( this, 6000 );  // Create a new datagram connection on port 6000
      //udp.log( true );            // &lt;-- printout the connection activity
      udp.listen( true );           // and wait for incoming message
  }
  
  
  void keyPressed() {
      String IPaddress  = "192.168.1.177"; // The remote IP address
      int port          = 8888;  // The destination port
      if (keyCode == UP)
      {
          udp.send("Test", IPaddress, port );
      }
      else
          if (keyCode == DOWN)
          {
              udp.send("Hello World", IPaddress, port );
          }
  }
  
  void receive( byte[] data ) {    // &lt;-- default handler
      //void receive( byte[] data, String IPaddress, int port ) { // &lt;-- extended handler
      for(int i=0; i &lt; data.length; i++)
          print(char(data[i]));
      println();
  }
  </code></pre>
  
  <p>How could I get the sketch to send the right messages?</p>
  
  <p>Of course I am more than willing to provide more information.</p>