what is Serial.read() returning?

I've written a small routine that should wait for a signal over serial before the program begins. It goes like:

boolean connectionEstablished = false;
byte connectByte=0;
void establishContact() {
while (!connectionEstablished){
if (Serial.available()>0){
connectByte = Serial.read();
if (connectByte=='X'){
Serial.println("Connection accepted");
connectionEstablished=true;
}else{
Serial.println("Invalid connection attempt:");
Serial.println(connectByte,DEC);
}
}else{
Serial.println("waiting for start signal");
}
delay(200);
}
}

Basically the program should wait for the character 'X' before leaving that while loop. This is a simple extension of the SerialCallResponse example.

The problem is that both this and that example exit the while loop if nothing is connected. I am using the bluetooth arduino. If I initiate a connection to the modem over bluetooth before the program starts then it waits in the loop as expected. If I don't have something connected then somehow the loop terminates. It is mind boggling!

If anyone has any ideas of what is happening here I'd love to hear them!

Regards,
Kallin Nagelberg.

If nothing is connected, how do you know the while loop is exited? :-?

I have an LED that is triggered after the loop is exited.'

I changed the loop to the following and it's functioning as expected. Still have no idea why the other way didn't work though,,

boolean connectionEstablished = false;
byte connectByte=0;
void establishContact() {
while (!connectionEstablished){
while (Serial.available() <= 0) {
Serial.print('A', BYTE); // send a capital A
delay(300);
}

connectByte = Serial.read();
if (connectByte=='X'){
Serial.println("Connection accepted");
connectionEstablished=true;
}else{
Serial.println("Invalid connection attempt:");
Serial.println(connectByte,DEC);
}

delay(200);
}
}

Huh. That's strange. Is it possible radio noise ended up as an 'X'? Does BlueTooth take care of reliably transmitting data?