通过 LiveConnect 将二进制数据从 Javascript 传递到 Java 小程序
我正在开发一个带有 javascript 前端的应用程序,它可以从服务器接收一堆八位字节(目前我使用 php 的 chr() 来模拟一些数据)。
事实证明,尝试将数据从 JavaScript 传递到小程序中进行操作是很困难的。由于数据可以在字符串中间有空值,所以看起来它在第一个空值进入时就终止了。看起来一旦二进制数据接触到 JavaScript 变量,编码就会与一些字节混淆(或者这可能只是一个问题)不管怎样
,我有哪些选项可以获取从服务器发送的二进制数据块并将其放入 Java 小程序中进行操作。如果我想保持数据完整性,转换为 Base64(或其他某种编码)是我唯一的选择吗?
所有这些对我来说都是新的,所以希望我能清楚地表达出来。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
啊,liveconnect 的祸根。
是的,您需要或使用
urlencode
或base64
来获取数据。即使在将内容从 JavaScript 传递到 Flash(或返回)时,您也需要这样做,因为中间的接口使用以 null 结尾的字符串(我知道这很愚蠢)。
Ah the bane of liveconnect.
Yes, you either need or use
urlencode
orbase64
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).
我认为当你的java脚本获取二进制数据并将其传递给java applet时的架构并不是最佳的。您是否想过修改小程序以使其直接访问服务器并获取二进制数据?没有任何java脚本吗?
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?