That will be determined by the way your application was designed. If your application starts, executes some commands and or process and the terminiates you have to write it is such a way as to wait for more data after the completion of the first cycle and the process more data or commands as it is received.
If you can elaborate on the exchane between the applications and what exactly you are trying to achieve is will be easier to give you better pointers in the right direction.
Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd