Processing Serial to Arduino

I am working on sending serial values from processing to arduino.
I have an arduino sketch that works with serial values sent from the arduino software's serial console. all it does is read the values and echo them back.
However when i use processing to send the same values issues start to happen.

in the arduino console when i send the string
'DRGBRGBRGBRGBRGBD'

it echos
"RGBRGBRGBRGBRGB"

however when i have processing send the same string it echos
"RGBRGBRGBRGBRGB

RGBRGBRGBRGRBRRBRG
RBRGBRGB

RGGRGRGRG
RG
RGBRGBRGBRGBRG"

the program attempted to send the string approximately 10 times during that echo

Im new to serial communication so hopefully someone can help me figure this out.

ARDUINO CODE

byte test[15];

void setup()
{
  Serial.begin(9600);  
}

void loop()
{
  if(Serial.available() >= 17)
  {
    if(Serial.read() != 'D')
    {
      delay(10);
      Serial.flush();
    }
     
     for(int i=0; i<15;i++)
     {
       test[i] = Serial.read();
     }
   
     if(Serial.read() == 'D')
     {

      for(int p=0 ; p<15 ; p++)
      {
        Serial.print(test[p]); 
      }
    
    Serial.println();
    Serial.println();
   }
  }

PROCESSING CODE

import processing.serial.*; 
Serial port; 
  long last =0;
void setup()
{
  size(200,200);
   println(Serial.list()); 
   port = new Serial(this, Serial.list()[0], 9600); 
}

void draw()
{
   if( millis() - last > 2000)
  {
   last = millis();
     
      port.write('D');
      port.write('R');
      port.write('G');
      port.write('B');
      port.write('R');
      port.write('G');
      port.write('B');
      port.write('R');
      port.write('G');
      port.write('B');
      port.write('R');
      port.write('G');
      port.write('B');
      port.write('R');
      port.write('G');
      port.write('B');
      port.write('D');
  }
}

You appear to be flushing the buffer if you don't receive a 'D' therefore throwing away the last 16 bytes plus any that arrive in the next 10mS.

If you are using the 'D' to synchronise your system make sure you actual echo it back (if that's what you want) and don't throw the baby out with the bath water.

i figured it out. i was looking at the echoed values in the arduino console. However when i added more to the program to check if the correct values had been read it had read them correctly.