简体   繁体   English

flex4套接字问题

[英]flex4 socket problem

I'm trying to communicate my flash application with my server. 我正在尝试将Flash应用程序与服务器通信。 Either the problem is my code is working on Flash Professional, but I have prepared all my interface on Flash Builder which uses Flex 4 -SDK. 可能是我的代码在Flash Professional上正常工作,但是我已经在使用Flex 4 -SDK的Flash Builder上准备了所有接口。 My code does not work on Flex Project. 我的代码在Flex Project上不起作用。

The problem is not security file. 问题不在于安全文件。 I can not solve the problem. 我无法解决问题。 What are the possible reasons? 可能是什么原因?

Kind Regards. 亲切的问候。

If necessary my code is below [working on FlashPro but not on Flex ! 如有必要,我的代码如下[在FlashPro上有效,但在Flex上无效! ] ]

import flash.net.*;
import flash.events.Event;var host:String = new String("127.0.0.1");
var port:int = 8080;
var securityFile:String = "http://localhost:1755/.../..../s....xml";
var bagli:Boolean = false;

var socket:Socket = null;

var veri:String = new String("----");

btnGonder.addEventListener(MouseEvent.MOUSE_DOWN, tiklantiEvent);

function buildSocket():void
{           
trace("beginning....");
    socket = new Socket();
    socket.addEventListener(Event.CONNECT, onConnect);
    socket.addEventListener(Event.CLOSE, onClose);
    socket.addEventListener(ErrorEvent.ERROR, onError);
    socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
    socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);


Security.allowDomain(host);

Security.loadPolicyFile(securityFile);


try {
    socket.connect(host, port);
    bagli = true;
    trace("--- connection...");

} catch (error:Error) {

    trace("--- connection failed...");
    socket.close();
}
}


 function send(string:String):void {
    socket.writeUTFBytes(string);
    socket.flush();
}
 function onConnect(event:Event):void {
    trace("connect");
}
 function onClose(event:Event):void {
    trace("closed");
}
 function onError(event:IOErrorEvent):void {
    trace("connection erron");
}
 function onIOError(event:IOErrorEvent):void {
    trace("data error");
}
 function onResponse(event:ProgressEvent):void {
    var string:String = socket.readUTFBytes(socket.bytesAvailable);
    trace(string);
}


function (sender:Event):void {
    trace("clicked button....");
    buildSocket();
    trace("------------------");

}

You are trying to authorize a socket connection by using a content-type policy file. 您正在尝试通过使用内容类型策略文件来授权套接字连接。 You should use socket policy file instead. 您应该改用套接字策略文件。 Policy file syntax is the same as far as I remember, but the url should begin with xmlsocket:// instead of http:// . 据我所知,策略文件的语法相同,但是url应该以xmlsocket://开头,而不是http:// This file should not be served through http. 此文件不应通过http提供。

Furthermore, the host's domain and the domain from the policy file address should be exactly the same. 此外,主机的域和策略文件地址中的域应完全相同。 Given that your host is specified as 127.0.0.1, change the policy file url to 假设您的主机指定为127.0.0.1,请将策略文件url更改为

xmlsocket://127.0.0.1:1755 xmlsocket://127.0.0.1:1755

For more details see Adobe's guidelines for policy files . 有关更多详细信息,请参阅Adobe的策略文件指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM