我想知道如何使用我的flex AIR項目中的AMF格式將數據發送到使用Java編寫的套接字。當使用writeUTFBytes()
方法發送數據時,我得到CorruptedStreamException
。有沒有人遇到類似的問題? AMF只能用於僅使用LCDS的情況嗎?如何將AMF格式的數據從flex發送到java套接字服務器?
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();
}
請添加一些代碼示例 – 2011-05-19 10:15:28