1

I have a SWF file embedded in a PHP web application. All local and on my system. I want to make a socket connection from my SWF to localhost:4242 (which is an eye tracker api). When I run SWF using flash player everything works fine. But when I run it from browser I get:

Security Error: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Security sandbox violation: http://localhost/graph/assets/swf/Graph.swf cannot load data from http://localhost:4242."]

I added crossdomain.xml to my local web server (easy php) like this:

<?xml version="1.0" ?>
  <cross-domain-policy>
  <site-control permitted-cross-domain-policies="master-only"/>
  <allow-access-from domain="*" to-ports="*" secure="false"/>
  <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

and this is my action script for socket connection:

socket = new Socket();
Security.allowDomain("*");
Security.allowInsecureDomain("*");
Security.loadPolicyFile("http://localhost/crossdomain.xml");
socket.addEventListener(Event.CONNECT, onSocketConnect);
socket.addEventListener(Event.CLOSE, onClose);
socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError);

socket.connect("http://localhost", 4242);

I went through everything on web for solving this problem. I don't know what the problem is and what should I do.

elahehab
  • 325
  • 3
  • 16
  • Welcome to the jungle! :) The reason is that you try to connect to different port! That's why you need to serve the crossdomain there. What server are you using? – Andrey Popov May 28 '15 at 11:12
  • @AndreyPopov I use easyPhp (I mentioned in the post) for my web app but eye tracker... I dont know. the eye tracker(which I want to connect to) is a device with tcp api. I connect to it via port 4242. so what should I do about it? – elahehab May 28 '15 at 11:29
  • 2
    The thing is that you connect to different server (with different port). This server needs to respond with the proper crossdomain.xml file. Usually it goes on port 843, so you can try to load it from there directly. Check out this article: http://krasimirtsonev.com/blog/article/Flash-sockets-and-cross-domain-policy-file-nodejs It's a tricky thing to do, but usually people open separate port for crossdomain and another one for proper connection (`4242` in your case) – Andrey Popov May 28 '15 at 11:54
  • @AndreyPopov hum, I moved my local server to port 843 and then tried "localhost:843/crossdomain.xml" and "xmlsocket://localhost:843/crossdomain.xml". still get the error! – elahehab May 28 '15 at 12:40
  • I don't understand what 'local server' means. Is your server ok to server crossdomain.xml file on port `843` and allow socket connections on port `4242` **at the same time** (talking about the very same server)? – Andrey Popov May 28 '15 at 13:02
  • @AndreyPopov I have an apache server on localhost:843 and I uploaded crossdomain.xml on this server and I can access it using localhost:843/crossdomain.xml. And I have an eye tracker which listens on port 4242. My swf is on localhost:843/graph/user/playGame. I want to make a socket connection to eye tracker on port 4242. – elahehab May 29 '15 at 11:27
  • Well see, the point is that the 'eye tracker' (whatever this is) is **separate server** (not apache). And flash is smart enough to know that you connect to a different thing. It's like running two servers and asking the first to allow you to connect to the second.. – Andrey Popov May 29 '15 at 11:29
  • @AndreyPopov So there is no way to connect to eye tracker from my apache server? :( – elahehab May 29 '15 at 11:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/79126/discussion-between-andrey-popov-and-elahehab). – Andrey Popov May 29 '15 at 11:36

0 Answers0