2 Replies Latest reply on Jun 23, 2010 6:53 PM by quoc_thai

    Policy File

    SOMEONEINTHEWORLD

      Hello,

       

      Can someone help me in sending policy file to flash player.  The below code is working fine (without policy file) in the IDE, but when i try it in browser it is not working.

       

      Thanks

       

      //Java Server

       

      import java.io.*;
      import java.io.PrintStream;
      import java.net.ServerSocket;
      import java.net.Socket;

       

      public class MultiThreadServer2 implements Runnable {
        Socket csocket;

       

        MultiThreadServer2(Socket csocket) {
          this.csocket = csocket;
        }

       

        public static void main(String args[]) throws Exception {
          ServerSocket ssock = new ServerSocket(1234);
          System.out.println("Listening");
          while (true) {
            Socket sock = ssock.accept();

       

            String policy = "<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>" + "\0";

       

            OutputStream os = sock.getOutputStream();
            os.write(policy.getBytes());

       

            System.out.println("Connected");
            new Thread(new MultiThreadServer2(sock)).start();
          }
        }

       

        public void run() {
          try {
            PrintStream pstream = new PrintStream(csocket.getOutputStream());
            pstream.println(" bottles of beer on the wall");

       

            BufferedReader br = new BufferedReader(new InputStreamReader(csocket.getInputStream()));

       

            String str = br.readLine();

       

            System.out.println(str);

       

            pstream.close();
            csocket.close();
          } catch (IOException e) {
            System.out.println(e);
          }
        }
      }

       

       

      //Flex

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
         
          <fx:Script>
              <![CDATA[
                  import mx.events.EventListenerRequest;
                  public var socket:Socket = new Socket();
                 
                 
                  public function init():void
                  {
                      socket.connect("localhost", 1234);
                     
                      socket.writeUTFBytes("hello \n");
                      socket.flush();
                     
                      socket.addEventListener(ProgressEvent.SOCKET_DATA, progressEvent);
                  }
                 
                  public function progressEvent(event:ProgressEvent):void
                  {
                      textarea.text += socket.readUTFBytes(socket.bytesAvailable);
                  }
              ]]>
          </fx:Script>
          <s:TextArea x="29" y="119" width="366" height="200" id="textarea"/>
         
         
      </s:Application>