Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
It also explains how to empty the input buffer.
It should not be necessary to empty the output buffer - the data in it will be sent (and the buffer emptied) even if there is nothing receiving the data,
...R