Different behaviour between Processing and Arduino Serial Monitor

i used this to turn led on or off

void ON() {
port.write(1);
}

void OFF() {
port.write(2);
}

 


and Arduino

void loop(){

if(Serial.available()){

int val = Serial.read();

if(val == 1){
digitalWrite(13, HIGH); //turn on
}
if(val == 2){ //if 2 received
digitalWrite(13, LOW); //turn off
}

}
}