take this as example , it is between two systems communicating on serial port. one sys send data and other rx it , parse it and then send appropriate ack
1 read a serial port buffer (wait for some time to avoid any data loss ). when all is well terminate the while loop
2 now parese the data as per requiremnt and display it
3 send ack to the sys1
4 repeat step 1 to see is there any data rx in reply of ack
put all above in flat sequence and put the seq in a while loop. all work fine.