Dual way serial communication

I'm trying to create a two way connection but i'm a little confused, i know it never exits the first while so my question is how do i get this code to detect if either port is receiving information and send it to the other port?

void setup()
{
   Serial.begin(9600);
   Serial3.begin(9600);
}
void loop(void)
{
  while(Serial.available());
  {
    Serial3.println(Serial.read() - '0');
  }
  while(Serial3.available());
  {
    Serial.println(Serial3.read() - '0');
  }
}

It will finish the first while loop when the serial buffer is empty. Ditto with the second while.

Replace the while with an if

AWOL:
Replace the while with an if

it keeps printing -49 continiously even if i dont send information through the port if i set it to if

Lose the semicolon.

AWOL:
Lose the semicolon.

Like this?

void setup()
{
   Serial.begin(9600);
   Serial3.begin(9600);
}
void loop(void)
{
  if(Serial.available())
  {
    Serial3.println(Serial.read() - '0');
    Serial.flush();
  }
  if(Serial3.available())
  {
    Serial.println(Serial3.read() - '0');
    Serial3.flush();
  }
}

Flush?

AWOL:
Flush?

Flush clears the serial buffer from what i've read

flush pauses until the serial transmit buffer has emptied itself.

Code is still not working

Why ae you changing the code every time you post?

AWOL:
Why ae you changing the code every time you post?

Trying to figure it out lol, if anyone can post the code which will work i'd be happy to replace it in the arduino.

Anyone got an example of two way serial communication coz i can't figure it out?

Sorry about this -> UP

ugh! anyone gonna help? ive busted my balls for 10 hours trying to figure this out.

Elitism:
ugh! anyone gonna help? ive busted my balls for 10 hours trying to figure this out.

An example that builds up to a duplex serial comms: Lab: Two-way (Duplex) Serial Communication using an Arduino and Processing – ITP Physical Computing

I'm not duplexing anything?

I'm getting the arduino to receive and send on two serial ports allowing two serialports to communicate with eachother

Serial TX: hello
Serial3 RX: hello
Serial3 TX: hi back
Serial RX: hi back

This is as basic as i can get the code but it dont work?

void setup()
{
   Serial.begin(9600);
   Serial3.begin(9600);
}
void loop(void)
{
  if(Serial.read())
  {
    Serial3.println(Serial.read() - '0');
  }
  if(Serial3.read())
  {
    Serial.println(Serial3.read() - '0');
  }
}

Elitism:

[quote author=The Clever Monkey link=topic=110772.msg832555#msg832555 date=1340151408]

Elitism:
ugh! anyone gonna help? ive busted my balls for 10 hours trying to figure this out.

An example that builds up to a duplex serial comms: Lab: Two-way (Duplex) Serial Communication using an Arduino and Processing – ITP Physical Computing

I'm not duplexing anything?

I'm getting the arduino to receive and send on two serial ports allowing two serialports to communicate with eachother

Serial TX: hello
Serial3 RX: hello
Serial3 TX: hi back
Serial RX: hi back

This is as basic as i can get the code but it dont work?

void setup()
{
   Serial.begin(9600);
   Serial3.begin(9600);
}
void loop(void)
{
  if(Serial.read())
  {
    Serial3.println(Serial.read() - '0');
  }
  if(Serial3.read())
  {
    Serial.println(Serial3.read() - '0');
  }
}

[/quote]

Ok, this is a pretty contrived (and, to me, not particularly useful) example.

But, why are you reading a byte and discarding it? Check out Serial.available() - Arduino Reference

Elitism:
ugh! anyone gonna help? ive busted my balls for 10 hours trying to figure this out.

The IDE includes an example called "MultiSerialMega".

void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte); 
  }
  
  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.write(inByte); 
  }
}

Thanks!