2 Replies Latest reply on Mar 15, 2010 8:02 PM by tooMuchTrouble

    Crossdomain.xml for socket !

    quoc_thai Level 1

      Hi all,

       

           From the link: http://giantflyingsaucer.com/blog/?p=15 I implemented socket communication.

           My port is: 8888, hostname is : quocthai.

       

           After that, I created flex project with server is IIS !

           The main mxml component is:

           -------------------------------

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

       

      <mx:Script>

      <![CDATA[

       

              private var sockExample:DotNetSocketExample = new DotNetSocketExample()

       

       

      private function send():void

      {

      sockExample.send(

      "hello");

      }

       

       

      private function disconnect():void

      {

      sockExample.disconnect();

      }

       

      ]]>

       

      </mx:Script>

       

       

      <mx:Panel width="468" height="116" layout="absolute" horizontalCenter="0" verticalCenter="0" backgroundColor="#EEEEEE" id="DotNetSocketConnectPanel" title="Dotnet Socket Connect Example">

       

      <mx:Button x="327" y="40" label="Disconnect" width="95" id="disconnect_btn" click="disconnect()"/>

       

      <mx:Button x="327" y="10" label="Send" width="95" id="send_btn" click="send()"/>

       

      <mx:TextInput x="21" y="10" width="298" id="send_txt" maxChars="100"/>

       

      </mx:Panel>

      </mx:Application>

      --------------------------------------

       

           My DotNetSocketExample.as is:

      package

      {

       

       

      import flash.events.*;

       

      import flash.net.XMLSocket;

       

      import flash.system.Security;

       

       

      public class DotNetSocketExample {

       

       

      private var hostName:String = "quocthai";

       

      private var port:uint = 8888;

       

      private var socket:XMLSocket;

       

       

       

      public function DotNetSocketExample() {

      socket =

      new XMLSocket();

      configureListeners(socket);

      Security.loadPolicyFile(

      "http://quocthai/crossdomain.xml");

      socket.connect(hostName, port);

      }

       

       

       

      public function send(data:Object):void {

      socket.send(data);

      }

       

       

      public function disconnect():void {

      socket.close();

      }

       

       

      private function configureListeners(dispatcher:IEventDispatcher):void {

      dispatcher.addEventListener(Event.CLOSE, closeHandler);

      dispatcher.addEventListener(Event.CONNECT, connectHandler);

      dispatcher.addEventListener(DataEvent.DATA, dataHandler);

      dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

      dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);

      dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

      }

       

       

      private function closeHandler(event:Event):void {

       

      trace("closeHandler: " + event);

      }

       

       

      private function connectHandler(event:Event):void {

       

      trace("connectHandler: " + event);

      }

       

       

      private function dataHandler(event:DataEvent):void {

       

      trace("dataHandler: " + event);

      }

       

       

      private function ioErrorHandler(event:IOErrorEvent):void {

       

      trace("ioErrorHandler: " + event);

      }

       

       

      private function progressHandler(event:ProgressEvent):void {

       

      trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);

      }

       

       

      private function securityErrorHandler(event:SecurityErrorEvent):void {

       

      trace("securityErrorHandler: " + event);

      }

      }

      }

       

      I have the crossdomain.xml:

      ---------------------------------

      <?xml version="1.0" encoding="UTF-8"?>
      <cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFile.xsd">
              <allow-access-from domain="*" to-ports="8888"/>
              <site-control permitted-cross-domain-policies="master-only"/>
      </cross-domain-policy>

      --------------------------------

       

      I tried copy crossdomain.xml file to IIS directory: C:\Inetpub\wwwroot and folder that contain my flex project: D:\Test\bin-debug

      I run my web at: http://quocthai/Test/bin-debug/Test.html

       

      Inside the policyfiles.txt log, I meet some errors such as:

      ---------------------------------

      OK: Root-level SWF loaded: http://quocthai/Test/bin-debug/Test.swf
      OK: Searching for <allow-access-from> in policy files to authorize data loading from resource at xmlsocket://quocthai:8888 by requestor from http://quocthai/Test/bin-debug/Test.swf
      OK: Policy file accepted: http://quocthai/crossdomain.xml
      Warning: [strict] Ignoring policy file at xmlsocket://quocthai:8888 due to incorrect syntax.  See http://www.adobe.com/go/strict_policy_files to fix this problem.
      Error: SWF from http://quocthai/Test/bin-debug/Test.swf may not connect to a socket in its own domain without a policy file.  See http://www.adobe.com/go/strict_policy_files to fix this problem.

      ----------------------------------------

       

      I read from link: http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security.html but I can't fix above errors. Please help me !