【问题标题】:Not able to receive message of 10 bytes using native messaging无法使用本机消息接收 10 字节的消息
【发布时间】:2014-07-02 09:50:13
【问题描述】:

我创建了一个简单的 chrome 扩展程序,以便通过 chrome 原生消息传递与 Windows 原生应用程序交互。

我能够在浏览器和应用程序之间发送和接收消息。但如果原生应用发送的消息长度为 10 或 2560,则扩展的 onmessage 事件监听器不会收到消息。

原生应用代码

char *test = "{\"tes\":\"\"}";
unsigned int tLen = strlen(test);
cout<< char(((tLen>>0) & 0xFF))
    << char(((tLen>>8) & 0xFF))
    << char(((tLen>>16) & 0xFF))
    << char(((tLen>>24) & 0xFF));
cout << test << flush;

如果我分配 char *test = "{\"test\":\"\"}"(带有额外的 t),它工作正常。

我不知道这个问题的原因是什么。

请帮忙!

谢谢!

【问题讨论】:

  • 请重新表述您的问题。问题不清楚,因为你没有解释什么不起作用
  • 对不起,句子中有错误。我已经更正了。

标签: c++ google-chrome google-chrome-extension chrome-native-messaging


【解决方案1】:

您传递数据长度的方式不正确,并且在长消息上也会失败。相反,试试这个:

char *test = "{\"tes\":\"\"}";
unsigned int tLen = strlen(test);
cout.write((char*)&tLen , 4);
cout << test << flush;

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-07-02
  • 1970-01-01
  • 2016-02-28
  • 2017-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多