Welcome to Dream.In.Code
Getting Help is Easy!

Join 131,601 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,094 people online right now. Registration is fast and FREE... Join Now!




Policy Files + XMLSocket = Driving me mad!

 
Reply to this topicStart new topic

Policy Files + XMLSocket = Driving me mad!

BetaWar
post 5 Oct, 2008 - 01:12 PM
Post #1


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,976



Thanked 77 times

Dream Kudos: 1175
My Contributions


Okay, I am attempting to set up a socket connection to a program I have made (simply printf things that are send via sockets to the screen and senda a message back, using Python) with my Flash frontend (to make it nice and able to run from the browser). The server (python) side is working fin, it recieves everythign like it is supposed to, and replies too. The problem is that when I am not running the flash portion within the Flash sandbox (Flash program using CTRL+Enter) the connection fails.

I have read that they (Adobe) has added something called Policy Files to their security measures after Flash Player 7.something, and as such I have attempted to implement one (that is stored on the client computer and connected to/read by the flash swf so it knows that it is allowed to connect).

Here is a look at my Policy File:
CODE
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
  SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
  <allow-access-from domain="*" />
</cross-domain-policy>


I think it should work fine (as it is copied from adobe's hlp files on policy files and modified to allow everything).

Here is the code that I am using with my Flash swf file:
CODE
System.security.loadPolicyFile("file:///C:\a_python\python_test_apps\socket_04_chat_test\crossdomain.xml");
var sock:XMLSocket = new XMLSocket();
sock.connect('localhost', 2727);
sock.onConnect = function(myStatus:Boolean){
if(myStatus){
  txt.text += "Connected\n";
  trace("Connected");
}
else{
  txt.text += "Connection Failed\n";
  trace("Connection failed");
}
}
sock.onData = function(msg:String){
txt.text += "Recieved: "+msg+"\n";
      trace("Recieved: "+msg);
}
sock.onClose = function(){
txt.text += "Connection Closed.";
trace("Connection Closed");
}
sock.send("testing it out - Flash style :)");


Where "file:///C:\a_python\python_test_apps\socket_04_chat_test\crossdomain.xml" is the absolute path to the policy file on my harddrive, and the server (python) script is in the same folder (which, if I have read thigns correctly is okay).

The problem is, that whenever I attempt to run the swf from the web the connection fails to work, and the server only prints out this:
<policy-file-request/>

It I am not mistaken I have already told the swf where it can find the policy file.

Now, what I need some help on it getting this to work, assuming that it is even possible in the first place (and assuming it isn't please tell me so I can stop wasting my time on it).

Any Thoughts?

Thanks in advance
User is offlineProfile CardPM

Go to the top of the page


DilutedImage
post 7 Oct, 2008 - 08:32 PM
Post #2


D.I.C Addict

Group Icon
Joined: 20 Nov, 2006
Posts: 642



Thanked 6 times

Dream Kudos: 25
My Contributions


A couple things:

- If your SWF is on the same domain as your server, then you do not need a cross-domain policy file. This is only required when the SWF is in a different domain (or sub-domain) than the server being connected to.
- loadPolicyFile is only required if your cross-domain policy file is not in the root directory of your domain.
- 'localhost' will not work for the connect method, as it'll attempt to connect to the client's local system. To connect to the web server's local system, use null or the server's url.

So, try this:
CODE
var sock:XMLSocket = new XMLSocket();
sock.connect(null, 2727);
sock.onConnect = function(myStatus:Boolean){
if(myStatus){
  txt.text += "Connected\n";
  trace("Connected");
}
else{
  txt.text += "Connection Failed\n";
  trace("Connection failed");
}
}
sock.onData = function(msg:String){
txt.text += "Recieved: "+msg+"\n";
      trace("Recieved: "+msg);
}
sock.onClose = function(){
txt.text += "Connection Closed.";
trace("Connection Closed");
}
sock.send("testing it out - Flash style :)");

I don't have a socket server setup though, so I haven't tested it. My response is based mostly on the Flash Help documentation, with a dash of cross-domain experience.

User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 8 Oct, 2008 - 04:49 AM
Post #3


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,976



Thanked 77 times

Dream Kudos: 1175
My Contributions


Thanks for the help, but I was able to find a tutorial out there that explained what I had been doing wrong, so it is working now.

User is offlineProfile CardPM

Go to the top of the page

DilutedImage
post 8 Oct, 2008 - 11:32 AM
Post #4


D.I.C Addict

Group Icon
Joined: 20 Nov, 2006
Posts: 642



Thanked 6 times

Dream Kudos: 25
My Contributions


Cool. Well, for the benefit of others that might read this, how'd you fix it?

This post has been edited by DilutedImage: 8 Oct, 2008 - 11:32 AM
User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 8 Oct, 2008 - 02:06 PM
Post #5


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,976



Thanked 77 times

Dream Kudos: 1175
My Contributions


Here is the link to the tutorial that I used.

http://blog.pettomato.com/?p=9

It is very close to what I submitted a few days ago, but is taking on more than I was doing with it.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 04:05AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month