3

this is my native-app code: https://stackoverflow.com/a/20235961/2021585

As long as I send small sized data through postMessage() it gets echoed back properly.

But when I try to send a long data/string like port.postMessage({text:'ospj..LONG-MSG...'})

it does NOT get echoed back and the communication ends!!!

Where should I change to make large sized data communication possible between them?

Community
  • 1
  • 1
rohitvk
  • 277
  • 3
  • 13
  • As per my setup, the limit I discovered is 254 characters. If string size exceeds this limit, then communication halts permanently. Is there anything that can be done to overcome this problem. I need to send considerably large amount of (base64 encoded)data to extension. – rohitvk Dec 03 '13 at 12:08
  • Is it possible to send multiple 254 characters data then later have them assembled into the full message when all of the data has been received? – John Odom Dec 03 '13 at 16:20

1 Answers1

4

In my testing, I haven't found a limit for data sent from the browser to the application (it's somewhere above 2MB). There is a 1MB limit for data sent from the application to the browser.

The code you linked has two bugs that keep it from working for long messages. First, it doesn't read the message length correctly (it sums the byte values of the message length rather than bit-shifting, so that a 257-byte message will be interpreted as being 2 bytes long), and second, when writing the message length on output, it uses little-endian byte order rather than the native-endian byte order that the messaging spec calls for.

Mark
  • 2,792
  • 2
  • 18
  • 31
  • Thanks for the explanation. I've corrected my reading logic as below: *instead of `t += getchar();` I'm doing, `t += std::pow(256.0f, i) * getchar();` – rohitvk Dec 04 '13 at 10:49
  • It is working with the large data. But I"m unable to figure out the sending part i.e writing to stdout taking care of endiannes. so it'd be helpful if you could provide a code snippet which is standard for such type of problem. Thanks in advance! – rohitvk Dec 04 '13 at 10:53
  • For situations like this where I need precise control over input or output, I prefer the C standard IO functions over C++ (note that mixing the two in a single program can cause problems). Using C standard IO, the code to print a C++ string would be something like this: unsigned int len = str.length(); fwrite(&len, 4, 1, stdout); fwrite(str.c_str(), len, 1, stdout); – Mark Dec 05 '13 at 06:39