Apache flex worker中的flex loadpolicy

Apache flex worker中的flex loadpolicy,apache-flex,sockets,Apache Flex,Sockets,我试图使用FlexWorkers来管理套接字连接,因为当接收大量数据时,它会冻结UI 但由于843端口未打开,我遇到了政策问题。因此,我尝试使用其他端口加载策略,但仍然存在安全错误,即应用程序正在尝试访问端口843上的策略文件 以下是我在worker内部用于加载策略的内容: Security.loadPolicyFile("xmlsocket://myServer:8888"); 我尝试使用java应用程序来提供该策略: public static void main(String[] arg

我试图使用FlexWorkers来管理套接字连接,因为当接收大量数据时,它会冻结UI

但由于843端口未打开,我遇到了政策问题。因此,我尝试使用其他端口加载策略,但仍然存在安全错误,即应用程序正在尝试访问端口843上的策略文件

以下是我在worker内部用于加载策略的内容:

Security.loadPolicyFile("xmlsocket://myServer:8888");
我尝试使用java应用程序来提供该策略:

public static void main(String[] args)
{


    String policy = "<?xml version=\"1.0\"?><!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">";
    policy += "<cross-domain-policy>"; 
    policy += "<allow-access-from domain=\"*\" to-ports=\"*\"/>";
    policy += "</cross-domain-policy>";


    ServerSocket s;
    try
    {
        s = new ServerSocket(8888);



    while(true)
    {
        try
        {
            Socket cli = s.accept();
            BufferedReader in = new BufferedReader(new InputStreamReader(cli.getInputStream()));
            OutputStreamWriter out = new OutputStreamWriter(cli.getOutputStream());

            System.out.println(in.read());

            out.write(policy+"\0");
            out.flush();
            cli.shutdownInput();
            cli.shutdownOutput();
            cli.close();
            System.out.println("Policy response sent");
            System.out.println(policy);
            System.out.println("Waiting for new request");

        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }
    }
    catch (IOException e1)
    {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }


}
publicstaticvoidmain(字符串[]args)
{
字符串policy=“”;
政策+=”;
政策+=”;
政策+=”;
服务器插座;
尝试
{
s=新服务器插座(8888);
while(true)
{
尝试
{
套接字cli=s.accept();
BufferedReader in=新的BufferedReader(新的InputStreamReader(cli.getInputStream());
OutputStreamWriter out=新的OutputStreamWriter(cli.getOutputStream());
System.out.println(in.read());
out.write(策略+“\0”);
out.flush();
cli.shutdownInput();
cli.shutdownOutput();
cli.close();
System.out.println(“发送的策略响应”);
System.out.println(策略);
System.out.println(“等待新请求”);
}
捕获(IOE异常)
{
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
}
捕获(IOE1异常)
{
//TODO自动生成的捕捉块
e1.printStackTrace();
}
}
我不知道出了什么问题,是不是我做错了什么


提前谢谢。

为了让它工作得更好,我刚刚将“out”类型改为PrintWriter

以下是工作代码:

public class FlexPolicy extends Thread {



private ServerSocket s;

private StringBuffer policyBuffer = new StringBuffer();
public static final String POLICY_REQUEST = "policy-file-request";

private Logger log = Logger.getLogger(FlexPolicy.class);

public FlexPolicy()
{
    String allowedPorts = MyConfig.getInstance().getValue("ports");
    policyBuffer.append("<?xml version=\"1.0\"?><cross-domain-policy>");
    policyBuffer.append("<allow-access-from domain=\"*\" to-ports=\""+allowedPorts+"\" />");
    policyBuffer.append("</cross-domain-policy>");
}


@Override
public void run()
{
    try
    {
        s = new ServerSocket(Integer.parseInt(MyConfig.getInstance().getValue("socket")));

        while(true)
        {
            log.debug("Waiting for policy request");
            Socket cli = s.accept();
            BufferedReader in = new BufferedReader(new InputStreamReader(cli.getInputStream()));
            PrintWriter out = new PrintWriter(cli.getOutputStream());

            String request = receive(in);
            log.debug("received request : |"+request+"| |"+POLICY_REQUEST+"|");
            log.debug(request.indexOf(POLICY_REQUEST));

            if(request.indexOf(POLICY_REQUEST)!=-1)
            {
                log.debug("policy matches");
                sendPolicy(out);
            }

            try
            {
                cli.shutdownInput();
                cli.shutdownOutput();
                cli.close();
            }
            catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    }
    catch(Exception e)
    {

    }
}


public void sendPolicy(PrintWriter out)
{
    out.println(policyBuffer.toString()+"\0");
    out.flush();
    log.debug("Policy sent");
}


public String receive(BufferedReader input) throws Exception
{
    String requete = "";
    int taille = 0;
    char[] cbuf = new char[1000];

    taille = input.read(cbuf, 0, cbuf.length);
    if (taille == -1)
    {
        return null;
    }
    else
    {
        requete += new String(cbuf).substring(0, taille);
        return requete;
    }
}
}
公共类FlexPolicy扩展线程{
专用服务器;
私有StringBuffer policyBuffer=新StringBuffer();
公共静态最终字符串POLICY\u REQUEST=“POLICY file REQUEST”;
私有记录器log=Logger.getLogger(FlexPolicy.class);
公共政策()
{
字符串allowedPorts=MyConfig.getInstance().getValue(“端口”);
policyBuffer.append(“”);
policyBuffer.append(“”);
policyBuffer.append(“”);
}
@凌驾
公开募捐
{
尝试
{
s=newServerSocket(Integer.parseInt(MyConfig.getInstance().getValue(“socket”));
while(true)
{
log.debug(“等待策略请求”);
套接字cli=s.accept();
BufferedReader in=新的BufferedReader(新的InputStreamReader(cli.getInputStream());
PrintWriter out=新的PrintWriter(cli.getOutputStream());
字符串请求=接收(in);
log.debug(“收到的请求:|”+请求+“| |”+策略请求+“|”);
log.debug(request.indexOf(POLICY_请求));
if(request.indexOf(POLICY_request)!=-1)
{
log.debug(“策略匹配”);
发送策略(out);
}
尝试
{
cli.shutdownInput();
cli.shutdownOutput();
cli.close();
}
捕获(例外e)
{
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
}
捕获(例外e)
{
}
}
公共无效发送策略(打印输出)
{
out.println(policyBuffer.toString()+“\0”);
out.flush();
log.debug(“策略已发送”);
}
公共字符串接收(BufferedReader输入)引发异常
{
字符串requete=“”;
int-taille=0;
char[]cbuf=新字符[1000];
taille=input.read(cbuf,0,cbuf.length);
如果(taille==-1)
{
返回null;
}
其他的
{
requete+=新字符串(cbuf)。子字符串(0,taille);
返回请求;
}
}
}