I am developing a macOS application which can communicate with google chrome extension through native messaging
.
I used google official documentation from here, so I received data from extension successfully (as is shown in below).
But when I tried to answer, I always get an error.
My response is in JSON format and it is:
{
"text":
"Client Started"
}
I use swift
for my viewController
and Objective-c++
for native messaging:
ViewController.swift:
let stream = StreamReader()
override func viewDidLoad() {
super.viewDidLoad()
stream.getStream()
stream.writeStream("{"text":"Client Started"}")
}
StreamReader.m:
- (void)WriteStream:(NSString *)JSONResponse {
NSString *JSONResponseArray = [NSString stringWithFormat:@"%@", JSONResponse];
std::string outMsg = [JSONResponseArray UTF8String];
unsigned int len = outMsg.length();
std::cout.write(reinterpret_cast<const char *>(&len), 4);
std::cout << outMsg.data() << std::flush;
}
Error:
Notice: I tried to change both response and its length, but the error is same in both situations.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…