Marc's answer contains some errors (inherited from the question) and will not work for messages with lengths that do not fit in one byte.
Chrome's protocol, when communicating with native apps is:
- requests to native app are received through stdin
- responses to Chrome are sent through stdout
Chrome doesn't deal well with Windows style \r\n so avoid that in the messages and set stdin mode to binary (so you can correctly read the request len and \n doesn't 'turn' into \r\n):
_setmode(_fileno(stdin),_O_BINARY);
The request and response messages are JSON with a 4 byte header (uint32) containing the length of the message: [length 4 byte header][message]
Reading the request header:
uint32_t reqLen = 0;
cin.read(reinterpret_cast<char*>(&reqLen) ,4);
Writing the response header:
cout.write(reinterpret_cast<char*>(&responseLen),4);