gpt4 book ai didi

c++ - 无法使用 native 消息接收 10 字节的消息

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:22:09 25 4
gpt4 key购买 nike

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

我能够在浏览器和应用程序之间发送和接收消息。但是,如果从 native 应用程序发送的消息长度为 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),它工作正常。

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

请帮忙!

谢谢!

最佳答案

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

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

关于c++ - 无法使用 native 消息接收 10 字节的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24527989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com