如何从Chrome扩展程序TO本机应用程序发送消息? [英] How to send message FROM Chrome extension TO Native app?

查看:240
本文介绍了如何从Chrome扩展程序TO本机应用程序发送消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用c ++编写的native-app。

I have a native-app written in c++.

我可以使用如何从原生应用程式到Chrome扩充功能传送邮件?

无法找出其他方法。

Chrome doc。状态:Chrome会在单独的进程中启动每个本机消息传递主机,并使用标准输入(stdin)和标准输出(stdout)与其进行通信。相同的格式用于在两个方向发送邮件:每个邮件使用JSON序列化,UTF-8编码,并且以本地字节顺序在前面加上32位邮件长度。

Chrome doc. states : Chrome starts each native messaging host in a separate process and communicates with it using standard input (stdin) and standard output (stdout). The same format is used to send messages in both directions: each message is serialized using JSON, UTF-8 encoded and is preceded with 32-bit message length in native byte order.

如何读取/解释由chrome-extension发送的stdin中的数据?

how do I read/interpret data from stdin, sent by the chrome-extension?

如何读取4byte长度信息以及发送的UTF-8编码的其余数据?

How do I read 4byte length information and also the rest of the data that is being sent UTF-8 encoded?

请帮助!

感谢!

推荐答案

从stdin读取json数据:

To read the json-data from stdin:

int _tmain(int argc, _TCHAR* argv[])
{

unsigned int length = 0;
//read the first four bytes (=> Length)
for (int i = 0; i < 4; i++)
{
    length += getchar();
}

//read the json-message
string msg = "";
for (int i = 0; i < length; i++)
{
    msg += getchar();
}
}

这篇关于如何从Chrome扩展程序TO本机应用程序发送消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆