【发布时间】:2014-12-02 06:54:36
【问题描述】:
我在 C++ 中使用本机主机,当我将 base64 从本机应用程序发送到大小为 base64 1M的chrome扩展(本机消息传递)时,程序出现错误“与本机消息传递主机通信时出错” 我的代码如下
int _tmain(int argc, _TCHAR* argv[])
{
std::cout.setf( std::ios_base::unitbuf );
unsigned int c, t=0;
inp="";
t=0;
// Sum the first 4 chars from stdin (the length of the message passed).
for (int i = 0; i <= 3; i++) {
//t += getchar();
t += std::pow(256.0f, i) * getchar();
}
// Loop getchar to pull in the message until we reach the total
// length provided.
for (int i=0; i < t; i++) {
c = getchar();
inp += c;
}
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;
return 0;
}
【问题讨论】:
-
那么,问题在哪里...?你想知道什么?
-
是的,这是设计使然,他们根本不接受大于 1M 的消息。您需要将其分解为一系列较小的消息并重新组合扩展程序中的数据。
-
@donaddon 你有声明的来源吗?
标签: c++ google-chrome visual-c++ google-chrome-extension chrome-native-messaging