I have a native app written in c++ and a chrome-extension.
I am communicating between them using 'chrome native messaging'.
Native-App code:
int main(int argc, char* argv[]) {
unsigned int a, c, i, t=0;
std::string inp; do {
inp="";
t=0;
// Sum the first 4 chars from stdin (the length of the message passed).
for (i = 0; i <= 3; i++) {
t += getchar();
}
// Loop getchar to pull in the message until we reach the total
// length provided.
for (i=0; i < t; i++) {
c = getchar();
inp += c;
}
// Collect the length of the message
unsigned int len = inp.length();
//// We need to send the 4 btyes of length information
std::cout << char(((len>>0) & 0xFF))
<< char(((len>>8) & 0xFF))
<< char(((len>>16) & 0xFF))
<< char(((len>>24) & 0xFF));
//// Now we can output our message
std::cout << inp <<std::endl;
flushall();
}while(cnt < 2 );
return 0; }
Here I'm reading message sent by chrome-extension on stdin. and sending the same message back by writing it on stdout.
Extension is using PostMessage()
This is working... BUT ..
When I put my program under continuous while loop, the flow executes only once!
i.e port.postMessage({'text':'hello_1'}) gets echoed back as expected but if I do
port.postMessage({'text':'hello_2'}) it doesn't get echoed back.
I'm unable to understand what the problem is. Does it require threading?
Please help!
Thanks!