I have written numerous WSTP applications that take data from Mathematica, manipulate it in combination with data retrieved from other sources, and then return it to Mathematica. See for example https://github.com/MichaelSternNYC
All of these have been set up for a single interaction -- Mathematica calls
wstpfunction[var1_Integer, var2_Integer] (or whatever) and this is received within C++ as
void wstpfunction(int var1, int var2) (or whatever). The C++ code does what it needs to and then returns data to Mathematica with
WSPutString() or one of its sister functions. The C++ application then terminates, though the WSTP link can be left installed, which speeds things up if
wstpfunction is called again. Though the link remains valid, the program stops running after returning its output and must be restarted when called again. This is important because the value of any static variables is lost between calls.
My current task involves repeated use of a subscription to an outside data service, and I need certain information to remain resident in the WSTP program between calls. How might one craft a WSTP program that doesn't quit until asked, and which can accept new input from Mathematica at any time?
psuedo-code for the WSTP program
static int holder = 0;
// This is our entry point
void wstpfunction(int var1, int var2)
holder = holder + var1 + var2;
This code would work, but would not save the value of holder between runs.