1

I'm working on an application with a javascript front end that can receive a bunch of octets from the server (for the time being I'm using php's chr() to simulate some data).

Trying to pass the data from javascript into an applet to be manipulated is proving difficult. Since the data can have nulls mid-string, it looks like it gets terminated at the first null going in. It also looks like once the binary data touches a javascript variable the encoding messes with some of the bytes (or maybe that's just a problem with how I'm displaying it)

Either way, what options do I have for taking a block of binary data, sent from a server and putting it into a Java applet to be manipulated. Is a conversion to base64 (or some other encoding) my only option if I want to maintain data integrity?

All this is new to me, so hopefully I got things across clearly.

cmjreyes
  • 246
  • 4
  • 12

2 Answers2

3

Ah the bane of liveconnect.
Yes, you either need or use urlencode or base64 to get your data through.

Even when passing stuff from JavaScript to Flash (or back) you need to this, because the interface in between uses null terminated strings (which is just stupid, I know).

Ivo Wetzel
  • 46,459
  • 16
  • 98
  • 112
  • Thanks for that, however it still looks like I'm losing some stuff en-route. I'm encoding with encodeURI() on the js side (escape() is depricated) and decoding with a URLDecoder on the java side. As per the docs they seem to match perfectly. One problem byte is 0xC0, which gets decoded as ffffffef ffffffbf ffffffbd. Any ideas? – cmjreyes Nov 26 '10 at 19:46
  • It looks like once Javascript touches it, I lose those higher number bytes. If I base64 it from my test server, it makes it fine into everything, however that's not a possibility. I'll have to figure something else out. – cmjreyes Nov 26 '10 at 21:03
  • 1
    Well JavaScript uses UTF16, you'll need to either manually fiddle around with `charCodeAt`. Or try some trick UTF8 encoding like `encodeURI(escape(String.fromCharCode("...")))` and to reverse `unescape(decodeURI(String.fromCharCode("...")))` – Ivo Wetzel Nov 26 '10 at 22:03
0

I think that architecture when your java script gets binary data and passes it to java applet is not optimal. Did you probably think to modify applet to make it to go directly to server and get the binary data? Without any java script?

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • It crossed my mind, however the applet is only used in certain situations and could not even be used (or loaded) for a particular users session. It's basically used for special processing of certain data. – cmjreyes Nov 25 '10 at 13:42