From: Uwe Kraft on
Dear all,
I'm currently trying to implement a client-server-structure (with TCP/IP) using C/C++ and the MATLAB-Engine.
My goal is, that the client sends some MATLAB-commands to the server, which evaluates these commands and
sends the result and/or the current status back. So far, the implementation for simple calculations (like '1+1' etc.) is no propblem.

In my case, I do not only send such simple calculations, I want to send some function-calls too. And under some
certain conditions, the execution of these calculations/function-calls lasts over 24 hours.
Within these 24 hours the client should be able to see the current status of the function-call.That's why I tried to use
"engOutputPuffer(...)" to write the current status "on the fly" into the buffer and send this buffer for example every second
over the network to the client (during the server is still executing this function). The function, that is called,
produces some output (within the function) with "fprintf(...)" to give a feedback of the current status.
It seems to me that "engEvalString(...)" doesn't write this output "on the fly" into the buffer.
It rather looks like "engEvalString(...)" writes all the temporary output (fprintf,etc.) and the result of the called function in
that moment into the buffer when the execution of the function is done.

I want to know, if there is a way to solve this kind of problem.

To give you a short example:
If the server receives the command "test" from the client ("test" is a function, look at the code below), the server code looks like this:

.
.
.

Engine *ep;
int BUFSIZE = 512;
char buff[BUFSIZE];

/* Start the Matlab Engine */

int* status = new int;

ep = engOpenSingleUse(NULL,NULL,status);



/* Check if engine is running... */

if(!ep)

{

cout << "starting MATLAB engine failed!" << endl;

return;

}



/* Set Engine invisible */

engSetVisible(ep,0);

/* Set Buffer */
buff[BUFSIZE]='\0';
engOutputBuffer(ep, buff, BUFSIZE);

engEvalString(ep,"test");
.
.
.

The function "test" lies in the MATLAB-path from the server and looks like this:
function test
i=0;
while(i<10)
fprintf('%d\n',i);
i = i + 1;
pause(1);
end

The server needs about 10secs until he is done executing this function.
By checking the content of the buffer "buff" after 10secs, i get the following result:
0
1
2 ...and so on.

To get the current status of the function call every second, I thought that I could create two threads.
The first thread represents the server that is listening for incoming messages and hands this messages over
to the MATLAB engine. The MATLAB engine uses "engEvalString(...)" (like above) to evaluate these commands and writes
the (temporary) results in the buffer "buff". The second thread displays the buffer "buff" once i a second (for example: "cout << server.buff << endl;").
This solution doesn't work because I don't get any output during the execution of the function "test" although
I'm trying to display the buffer each second.

If I start both threads at the same time. The second thread displays for 10secs nothing and after
10secs it displays "0 1 2 3 ...9". This means, that if I let the function "test" count up to 3600, there will be
60 minutes nothing to see and after that there wil be 3600 lines in one moment.

That's why I'm looking for a method, which allows to get every second the current status of the buffer.
0 => 0 1 => 0 1 2 => 0 1 2 3 and so on...

I suppose the problem is, that "engEvalString(...)" writes the output into the buffer in that moment,
after the given command was executed. At the moment it looks like I can't access this information "on the fly"/
during execution, instead I have to wait until the function-call is done. After that I'm able to see the all the output of
my function in the buffer.

(Sorry for my bad english)

I hope you can help me!
Thanks!

Yours,
schlitz
From: schlitz needs help on
Push
From: schlitz needs help on
push
 | 
Pages: 1
Prev: vector division
Next: Processing Tiled Images