0

ソケット接続を管理するためにフレックスワーカーを使用しようとしています。これは、大量のデータを受信して​​いるときにUIがフリーズするためです。

しかし、ポート843が開いていないため、ポリシーに問題が発生しています。そのため、他のポートを使用してポリシーを読み込もうとしましたが、アプリケーションがポート843のポリシーファイルにアクセスしようとしているというセキュリティエラーが発生します。

ポリシーをロードするためにワーカー内で使用するものは次のとおりです。

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();
    }


}

何が悪いのかわかりませんが、何か間違ったことはありますか?

前もって感謝します。

4

1 に答える 1

0

うまく機能させるために、「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;
    }
}
}
于 2013-02-22T14:55:03.860 に答える