tags:

views:

71

answers:

1

Hi,

I'm trying to communicate my flash application with my server. Either the problem is my code is working on Flash Professional, but I have prepared all my interface on Flash Builder which uses Flex 4 -SDK. My code does not work on Flex Project.

The problem is not security file. I can not solve the problem. What are the possible reasons?

Kind Regards.

If necessary my code is below [working on FlashPro but not on Flex ! ]

import flash.net.*;
import flash.events.Event;var host:String = new String("127.0.0.1");
var port:int = 8080;
var securityFile:String = "http://localhost:1755/.../..../s....xml";
var bagli:Boolean = false;

var socket:Socket = null;

var veri:String = new String("----");

btnGonder.addEventListener(MouseEvent.MOUSE_DOWN, tiklantiEvent);

function buildSocket():void
{           
trace("beginning....");
    socket = new Socket();
    socket.addEventListener(Event.CONNECT, onConnect);
    socket.addEventListener(Event.CLOSE, onClose);
    socket.addEventListener(ErrorEvent.ERROR, onError);
    socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
    socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);


Security.allowDomain(host);

Security.loadPolicyFile(securityFile);


try {
    socket.connect(host, port);
    bagli = true;
    trace("--- connection...");

} catch (error:Error) {

    trace("--- connection failed...");
    socket.close();
}
}


 function send(string:String):void {
    socket.writeUTFBytes(string);
    socket.flush();
}
 function onConnect(event:Event):void {
    trace("connect");
}
 function onClose(event:Event):void {
    trace("closed");
}
 function onError(event:IOErrorEvent):void {
    trace("connection erron");
}
 function onIOError(event:IOErrorEvent):void {
    trace("data error");
}
 function onResponse(event:ProgressEvent):void {
    var string:String = socket.readUTFBytes(socket.bytesAvailable);
    trace(string);
}


function (sender:Event):void {
    trace("clicked button....");
    buildSocket();
    trace("------------------");

}
A: 

You are trying to authorize a socket connection by using a content-type policy file. You should use socket policy file instead. Policy file syntax is the same as far as I remember, but the url should begin with xmlsocket:// instead of http://. This file should not be served through http.

Furthermore, the host's domain and the domain from the policy file address should be exactly the same. Given that your host is specified as 127.0.0.1, change the policy file url to

xmlsocket://127.0.0.1:1755

For more details see Adobe's guidelines for policy files.

Vladimir Grigorov
your solution does not work, too :( My swf-file build with Flex make a connection, but can not receive or send anything. On the swf-file build with Flash Pro Cs5 it works ... The codes and the policy files are the same ... I've used socket policy file, the situation is the same :(
softwaremonster
What is the output of the traces? Do you have a dedicated service that listens on port 1755 and returns the socket policy?
Vladimir Grigorov
On flash pro cs5 the trace are ok. I can send and receive packet. But on Flex I can not do it... I've written to me on C# a server [Tcp Server]. I can not understand the code works on Cs5 but not on Flex :(
softwaremonster