Haxe Forum > Flash XMLSocket and Error #2048

  • Hi everyone,

    I am writing an IRC client in flash using Haxe, but I have problems getting it connect to the server. The XMLSocket connection always fail on "Error #2048". I searched a lot on google (I'm on that bug for two days now), but never found any working solution. I putted the -D network-sandbox flash in the .hxml file, tried to load policy files using

            flash.system.Security.allowDomain('*');
            flash.system.Security.allowInsecureDomain("mydomain.com");
            flash.system.Security.loadPolicyFile("http://mydomain.com/crossdomain.xml");

    but I just don't work. I also made a server listening on port 843 that sends the policy file, I actually can see it getting the connection but it still gives me an error 2048 on the flash side. I even tried to shut down the IRC software and put my policy file server on the 6667 port and send the policy file first, then a small hello, but still getting error 2048 (this time, the server is not even reached).

    Here is the crossdomain.xml file

    <?xml version="1.0"?>
    <cross-domain-policy>
    <allow-access-from domain="*" to-ports="843,6667" secure="false" />
    </cross-domain-policy>

    and finally the Haxe code

    import flash.net.Socket;
    import flash.events.Event;
    
    class IRCClient {
        
        /// Members : Public
        // Event functions
        public dynamic function f_evt_connected();
        public dynamic function f_evt_closed();
            
        /// Members : Private
        // Master socket
        private var m_socket:Socket;
        // Raw command list
        private var m_commandList:Array<Dynamic>;
        
        /// Functions
        
        // Initialise the IRC connection
        // Normally, the connection informations are received by parameters, but its hardcoded for debugging
        public function new(a_host:String, a_port:Int) {
            
            // Create the socket
            m_socket = new Socket();
            
            // Initialise command array
            m_commandList = new Array<Dynamic>();
            
            // Listen to every possible events
            m_socket.addEventListener("connect", eventConnected);
            m_socket.addEventListener("close", eventClosed);
            m_socket.addEventListener("data", eventData);
            m_socket.addEventListener("ioError", eventIoError);
            m_socket.addEventListener("securityError", eventSecurityError);
            
            flash.system.Security.allowDomain('*');
            flash.system.Security.allowInsecureDomain("mydomain.com");
            flash.system.Security.loadPolicyFile("http://mydomain.com/crossdomain.xml");
            
            // Connect to the server
            m_socket.connect("mydomain.com", 6667);
        }
        
        /// Socket IO functions
        // Connected
        private function eventConnected(eventData:Event) {
            trace("Socket successfully connected!");
        }
        
        // Closed
        private function eventClosed(eventData:Event) {
            trace("Socket closed by server.");
        }
        
        // IO Error
        private function eventIoError(eventData:Event) {
            trace("Erreur d'entrée/sortie");
        }
        
        // Security error
        private function eventSecurityError(eventData:flash.events.SecurityErrorEvent) {
            trace("Erreur de sécurité: " + eventData);
        }
        
        // Data received
        private function eventData(eventData:flash.events.DataEvent) {
            trace("Data: " + eventData.data);
        }
    }

    I even went to the flash control panel to allow everything, deleted my .adobe and .macromedia folders (I'm a linux users)

    I don't know what to do now, that's why I am asking for help here.

    Thanks!

  • Ok, I finally fixed it by myself.

    It looks like flash didn't liked the way I sent the data on port 843, and now it's working.

    I made a simple server in PHP to send the XML file (which I edited a bit, according to the Adobe website (but I don't know if it changed anything...)

    #!/usr/bin/php
    <?php
    
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    
    socket_bind($socket, "0.0.0.0", 843);
    
    socket_listen($socket, 10);
    
    while($client = socket_accept($socket)){
        echo "Client connected\n";
        
        $xml = <<< ENDXML
    <?xml version="1.0"?> 
    <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> 
    <cross-domain-policy>  
        <allow-access-from domain="*" to-ports="6667-6669,2222" />  
    </cross-domain-policy>
    ENDXML;
        socket_write($client, $xml);
        socket_send($client, "\0", 1, MSG_EOR);
        socket_close($client);
    }
    
    socket_close($socket);
    
    ?>

    I think I was missing the zero byte (\0) at the end... At least now it works!

< Prev | Page 1 / 1 | Next >