[Solved]Help with socket policy files.

6 posts

Flag Post

I’ve written a C sharp server program and a as3 client program. They work fine when I run the flash client in debug inside IDE, but not when I move the client anywhere which I’ve discovered is because I need to send a policy file to the flash client. However, after the server sends the policy file it executes the Socket.Receive(byte[] b) function but with nothing to receive, and the client never connects to the server (connect function never calls) but no error messages. My best guess is that the policy file is wrong but I’ve tried altering it in many ways, none of which have worked.
C sharp server:

private static TcpListener myLis;
private static Socket socket;
public static void Main(string[] args)
{
	myLis = new TcpListener(IPAddress.Parse("192.168.0.5"), 8002);
	myLis.Start();
	socket = myLis.AcceptSocket();
	
        // some code removed to keep post short-ish
	if(Regex.IsMatch(receivedText, "<policy-file-request/>\0"))
	{
		Console.WriteLine("matched policy file request!");
		String policyFile = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
			"<!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\"&gt;" + 
			"<cross-domain-policy>" + 
			"<site-control permitted-cross-domain-policies=\"all\"/>" + 
			"<allow-access-from domain=\"*\" to-ports=\"*\" secure=\"false\"/>" + 
			"<allow-http-request-headers-from domain=\"*\" headers=\"*\" secure=\"false\"/>" +
			"</cross-domain-policy>\0";
			Char[] characterList = policyFile.ToCharArray();
			byte[] toSend = new Byte[characterList.Length];
			for ( int po = 0; po < characterList.Length; po ++)
			{
			        toSend[po] = (byte) Convert.ToByte(characterList[po]);
			}
    			socket.Send(toSend);
	}
	// code that was here received and read 3 bytes sent by client to check connection is working
}

Flash Client simply connects to server and sends 3 bytes on the connect event. I have been running the client by right-click menu, open with internet explorer.
Thank you for your time.

 
Flag Post

No no no, don’t send the cross domain policy as a socket connection. You need to have an actual file on the server (at the domain root, eg. www.yoursite.com/crossdomain.xml) because the policy file is requested automatically by the flash player.

You do need to tell it what file to load and where it is, though:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Security.html#loadPolicyFile%28%29

(While it says you can have policy files in subdirectories, a change to Flash Player 10 made it so that there needed to be a global policy file that has to allow the connection and subdirectory files can only deny additional connections, but not permit extra ones; that change messed up one of my games pretty bad back when it happened).

 
Flag Post

Thanks for the help Draco, unfortunately it still doesn’t work. I was thinking, do I need to get the server program hosted on a website, because so far I’ve just been running it from my computer.

 
Flag Post

Or actually run a server on your machine. Inside the Flash IDE, Flash pretends to have 100% access permissions (because it’s a testing environment).

But yes.

 
Flag Post
Originally posted by Draco18s:

Or actually run a server on your machine. Inside the Flash IDE, Flash pretends to have 100% access permissions (because it’s a testing environment).

But yes.

Haha, totally forgot that fact for a while. I was super confused at how playerio was running their socket based server locally with no crossdomain.xml

 
Flag Post

I’ve fixed my problem. Here’s what I did:
1. Made a socket connection with port 843.
2. Send policy file over 843 port socket.
3. When its connects, make ANOTHER socket connection on an unused port (which is almost any) 8002, 8801, 950, 7086 etc.
4. Use the second socket to send and receive data.

Wow, that was a bit of a hassle.