how to handle chrome.runtime.sendNativeMessage() in native app

前端 未结 2 1998
广开言路
广开言路 2021-01-03 10:15

I am working on native messaging host. I am able to launch my custom application by using api

var port = chrome.runtime.connectNative(\'com.my_company.my_app         


        
2条回答
  •  情书的邮戳
    2021-01-03 10:54

    I am posting c++ code which will communicate i.e receives and sends the messages to chrome extension. Hope this will help to other developer

    int _tmain(int argc, _TCHAR* argv[])
    {
        cout.setf( std::ios_base::unitbuf ); //instead of "<< eof" and "flushall"
        _setmode(_fileno(stdin),_O_BINARY);
    
    
        unsigned int c, i, t=0;
        string inp;  
        bool bCommunicationEnds = false;
    
        bool rtnVal = true;
        do {
    
            inp="";
            t=0;
            //Reading message length 
            cin.read(reinterpret_cast(&t) ,4);
    
            // Loop getchar to pull in the message until we reach the total
            //  length provided.
            for (i=0; i < t; i++) {
                c = getchar();
                if(c == EOF)
                {
                    bCommunicationEnds = true;
                    i = t;
                }
                else
                {
                    inp += c;
                }
            }
    
             if(!bCommunicationEnds)
            {
                //Writing Message length
                cout.write(reinterpret_cast(&inp),4); 
                //Write original message.
                cout<

提交回复
热议问题