title: communication between native-app and chrome-extension
body: <p>I have a native app written in c++ and a chrome-extension.</p>
  
  <p>I am communicating between them using 'chrome native messaging'.</p>
  
  <p>Native-App code:</p>
  
  <pre><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 &lt;= 3; i++) {
      t += getchar();
    }
  
    // Loop getchar to pull in the message until we reach the total
    //  length provided.
    for (i=0; i &lt; 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 &lt;&lt; char(((len&gt;&gt;0) &amp; 0xFF))
            &lt;&lt; char(((len&gt;&gt;8) &amp; 0xFF))
            &lt;&lt; char(((len&gt;&gt;16) &amp; 0xFF))
            &lt;&lt; char(((len&gt;&gt;24) &amp; 0xFF));
  //// Now we can output our message
  std::cout &lt;&lt; inp &lt;&lt;std::endl;
  flushall();
  }while(cnt &lt; 2 );
  return 0;  }
  </code></pre>
  
  <p>Here I'm reading message sent by chrome-extension on stdin. and sending the same message back by writing it on stdout.</p>
  
  <p>Extension is using PostMessage()</p>
  
  <p>This is working... BUT ..</p>
  
  <p>When I put my program under continuous while loop, the flow executes only once!</p>
  
  <p>i.e port.postMessage({'text':'hello_1'}) gets echoed back as expected but if I do</p>
  
  <p>port.postMessage({'text':'hello_2'}) it doesn't get echoed back.</p>
  
  <p>I'm unable to understand what the problem is.  Does it require threading?</p>
  
  <p>Please help!</p>
  
  <p>Thanks!</p>