I got this from the chrome-added group and it WORKS for me.
The insert is the same:
The problem is probably related to the header, which contains the four-byte length of the message. If this is strange, Chrome will break the connection. Since stdout is in text mode by default, some ASCII characters can be converted to different characters in Windows, such as \ n becomes \ r \ n. You have more bytes in the header than you need, so the Chrome extension will assume that you send millions of bytes of data, become confused and disconnect, and some of the bytes of the header will expire in the message, causing the JSON parser to encounter unexpected characters.
Try setting stdout to binary mode:
_setmode(_fileno(stdout), _O_BINARY);
If this does not help, you can additionally try this alternative method of writing to standard output:
unsigned int len = final_msg.length(); fwrite(&len, 4, 1, stdout); printf("%s", final_msg.c_str()); fflush(stdout);
You may need to add some of them: fcntl.h io.h
source share