communication between native-app and chrome-extension

前端 未结 3 1155
栀梦
栀梦 2020-12-05 21:53

I have a native app written in c++ and a chrome-extension.

I am communicating between them using \'chrome native messaging\'.

Native-App code:



        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 21:58

    This works for me:

     int main(int argc, char* argv[])
     {
    
     std::cout.setf( std::ios_base::unitbuf ); //instead of "<< eof" and "flushall"
     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;
    }
    

    ...

提交回复
热议问题