如何从flex向java套接字服务器发送AMF格式的数据?
我想知道如何使用 AMF 格式将数据从我的 Flex AIR 项目发送到用 Java 编写的套接字。使用 writeUTFBytes()
方法发送数据时,我收到 CorruptedStreamException
。有人遇到过类似的问题吗?另外,如果我仅使用 LCDS,是否可以使用 AMF?
private SimpleServer(int port)
{
System.out.println(">> Starting SimpleServer on port " + port);
try
{
socket = new ServerSocket(port);
incoming = socket.accept();
objectInputStream = new ObjectInputStream(incoming.getInputStream());
objectOutputStream = new ObjectOutputStream(incoming.getOutputStream());
boolean done = false;
while (!done)
{
Object obj = objectInputStream.readObject();
System.out.println( obj.toString() );
if(obj == null)
{
done = true;
incoming.close();
}
}
}
catch (Exception e)
{
System.out.println(e);
}
}
我的 as3 向服务器发送数据的函数是
private function onSendClick():void
{
var host:String = "10.87.118.8";
var port:int = 9090;
var socket:Socket = new Socket();
trace("Connect");
socket.connect(host, port);
trace("write");
socket.writeUTFBytes("HelloSocket");
trace("flush");
socket.flush();
}
i want to know how to send data using the AMF format from my flex AIR project to a socket written in Java. I am getting CorruptedStreamException
when sending data using writeUTFBytes()
methods. Has anyone experienced similar problems? Also can AMF be used only if i am using LCDS only?
private SimpleServer(int port)
{
System.out.println(">> Starting SimpleServer on port " + port);
try
{
socket = new ServerSocket(port);
incoming = socket.accept();
objectInputStream = new ObjectInputStream(incoming.getInputStream());
objectOutputStream = new ObjectOutputStream(incoming.getOutputStream());
boolean done = false;
while (!done)
{
Object obj = objectInputStream.readObject();
System.out.println( obj.toString() );
if(obj == null)
{
done = true;
incoming.close();
}
}
}
catch (Exception e)
{
System.out.println(e);
}
}
And my as3 function to send data to the server is
private function onSendClick():void
{
var host:String = "10.87.118.8";
var port:int = 9090;
var socket:Socket = new Socket();
trace("Connect");
socket.connect(host, port);
trace("write");
socket.writeUTFBytes("HelloSocket");
trace("flush");
socket.flush();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AMF 代表操作消息格式。
它是定义如何在 ActionScript 客户端和外部系统之间传输数据的规范。
因此,许多服务器端技术将 AMF 纳入其软件包中。
例如 BlazeDS、GraniteDS、pyAMF、amfphp...
因此,为了回答您的问题,AMF 也不能在 LCDS 之外使用。
它只是一个“信封”,您可以用它来发送消息(=数据)。
它甚至应该与套接字一起使用。
我相信有一个名为 merapi 的开源库就使用了这一原理。
干杯
AMF stands for Action Message Format.
It is a specification which defines how to transfer data between an ActionScript client and external system.
Therefore, many server side technologies incorporate AMF into their packages.
For example BlazeDS, GraniteDS, pyAMF, amfphp, ...
Hence, to answer your question, no AMF can also be used outside of LCDS.
It is merely an "envelope" you can use to send your message (=data) in.
It should even work with sockets.
I believe there is an open source library called merapi that uses this principle.
Cheers
现在这是一个老问题了,但是由于在 ActionScript 端您正在使用
Java 端,因此将其更改为这样,它将在没有 AMF 的情况下工作:
This is an old question now, but since, on the ActionScript side you are using
On the Java side, change it to this and it will work without AMF :