AS3 无法从 Java 发送的套接字解码 AMF3 对象
我有一个 java 套接字服务器,它在连接时将 Animal 对象发送到 Flash 客户端。 对象是这样发送的:
Amf3Output amf3Output = new Amf3Output(SerializationContext.getSerializationContext());
amf3Output.setOutputStream(userSocket.getOutputStream());
amf3Output.writeObject(animal);
Flash 端的代码是:
var object:Object = socket.readObject();
trace(object);
trace(object as Animal);
但是,当第二个跟踪给我一个 null 时,
我检查了 java 发送了 31 个字节,Flash 接收了 31 个字节。
我认为我的 Java 和 AS3 类可能不符合某些 AMF 要求。
Java 类:
package main;
public class Animal {
public String name;
public int age;
}
AS3 类:
package
{
[Bindable]
[RemoteClass(alias="main.Animal")]
public class Animal
{
public var name:String;
public var age:int;
}
}
I have a java socket server that sends an Animal object to the Flash client when it connects.
The object is sent like this:
Amf3Output amf3Output = new Amf3Output(SerializationContext.getSerializationContext());
amf3Output.setOutputStream(userSocket.getOutputStream());
amf3Output.writeObject(animal);
And the code on flash side is:
var object:Object = socket.readObject();
trace(object);
trace(object as Animal);
However when the second trace gives me a null
I have checked that java sends out 31 bytes and Flash receives 31 bytes.
I think it might be that my Java and AS3 classes don't match some AMF requirement.
Java class:
package main;
public class Animal {
public String name;
public int age;
}
AS3 class:
package
{
[Bindable]
[RemoteClass(alias="main.Animal")]
public class Animal
{
public var name:String;
public var age:int;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不熟悉 Java 和可用的 AMF 序列化器/反序列化器,但闪存确实支持通过套接字发送类型化对象,并且如果发送正确的数据,则可以正常工作。下面是 ruby 中的套接字服务器与 Flash 应用程序通信的示例。我使用 RocketAMF 在连接后通过套接字将 AMF3 对象发送到客户端。
SocketTest.as:
socket_server.rb:
I'm not familiar with Java and the AMF serializers/deserializers available for it, but sending typed objects over sockets is indeed supported in flash, and works properly if you send the right data. Below is an example of a socket server in ruby communicating with a Flash application. I'm using RocketAMF to send an AMF3 object over the socket to a client after it connects.
SocketTest.as:
socket_server.rb:
您是否检查过 ActionScript 端的
objectEncoding
设置为 3?如果您发送 AMF3 数据并且它尝试读取 AMF0 数据,则它将无法工作。Have you checked that the
objectEncoding
is set to 3 on the ActionScript side? If you're sending AMF3 data and it's trying to read AMF0 data, it won't work.由于您已经使用了 BlazeDS,因此很难确定 AMF3 要求与 BlazeDS 要求是什么。我要说的是,BlazeDS 需要遵循 Java Beans 规范的 Java 类,这意味着匹配 getter 和 setter。
我还假设 Flex 端需要更多的东西来反序列化 AMF3 有效负载:在线格式不是 Actionscript 3.0 对象。我已经完成了一些 BlazeDS 自定义序列化,这就是为什么我认为您在 Flex 方面缺少一些东西。
您不使用 BlazeDS(或 GraniteDS)进行通信有什么原因吗?
Since you've taken parts of BlazeDS, it's hard to determine what are AMF3 requirements versus BlazeDS requirements. What I will say is that BlazeDS needs Java classes that follow the Java Beans spec and that means matching getters and setters.
I'm also assuming that more is needed on the Flex side to de-serialize the AMF3 payload: the on-the-wire format is not an Actionscript 3.0 object. I've done some BlazeDS custom serialization which is why I think you're missing something on the Flex side.
Is there a reason you're not using BlazeDS (or GraniteDS) for the communication?