Unable to connect, as no valid crossdomain policy was found

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

nwalsh
Posts: 2
Joined: 14 May 2012, 19:17

Unable to connect, as no valid crossdomain policy was found

Postby nwalsh » 14 May 2012, 20:59

Hi all,

I've been trying to get a Web Player build to work for a couple of days now and have had no luck despite looking in both the Unity forums and Smart Fox Server forums. I have made some progress in getting the sockets connected with the defaults, but I keep getting this error:

[SFS - ERROR] TCPSocketLayer: General exception on connection: Unable to connect, as no valid crossdomain policy was found at System.Net.Sockets.Socket.Connect_internal (IntPtr sock, System.Net.SocketAddress sa, System.Int32& error, Boolean requireSocketPolicyFile) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in <filename unknown>:0
at System.Net.Sockets.Socket.Connect (System.Net.IPAddress address, Int32 port) [0x00000] in <filename unknown>:0
at Sfs2X.Core.Sockets.TCPSocketLayer.ConnectThread () [0x00000] in <filename unknown>:0

I've looked at the Security Sandbox page provided by Unity and it explains that the webplayer only supports '*' in the domain access portion of the crossdomain.xml and that the to-ports portion is mandatory. Currently my crossdomain.xml (located in ".../SFS2X/config/crossdomain.xml) reads:

Code: Select all

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
   <!-- This is a master-policy file. site-control can be all,none,master-only -->
   <site-control permitted-cross-domain-policies="all"/>

   <!-- Instead of setting to-ports="*", administrators can use ranges and commas -->
   <!-- This will allow access to ports 123, 456, 457, and 458 -->
   <allow-access-from domain="*" to-ports="843, 9933" />
</cross-domain-policy>
<AutoSendPolicyFile>true</AutoSendPolicyFile>


This is just the default xml that was supplied in the installation of SmartFoxServer 2x except that I've added 'to-ports' 843 and 9933. I've added both of those ports as TCP to the socket addresses in the server configurator of the Admin tool. I've also double checked that "Use Flash Master Socket Policy" is set to true and that the Flash policy XML file is pointed at the crossdomain.xml file. I've tried everything I have found in the Unity forums and Smart Fox forums related to this. Some have said that Unity doesn't recognize the "site-control" attribute so I've tried commenting that line out, restarted SFS2X, and tried again and to no avail.

Does anyone have any ideas of what the problem could be?
nwalsh
Posts: 2
Joined: 14 May 2012, 19:17

Re: Unable to connect, as no valid crossdomain policy was fo

Postby nwalsh » 15 May 2012, 01:50

After a few more hours I decided to do a fresh install of SFS2X, made the necessary changes in the admin tool and altered the cross domain policy to include port 843. It fixed the problem. The new policy looks like this:

Code: Select all

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
   <!-- This is a master-policy file. site-control can be all,none,master-only -->
   <site-control permitted-cross-domain-policies="all"/>

   <!-- Instead of setting to-ports="*", administrators can use ranges and commas -->
   <!-- This will allow access to ports 123, 456, 457, and 458 -->
   <allow-access-from domain="*" to-ports="843, 9933" />
</cross-domain-policy>


It's possible that the AutoSendPolicyFile tag is what was stopping me. Someone else must have altered the file before I got to it since it wasn't in the file when I did a fresh install. Hope this helps anyone else who may end up with the Web Player troubles!
Jake-GR
Posts: 59
Joined: 28 Dec 2011, 22:52

Re: Unable to connect, as no valid crossdomain policy was fo

Postby Jake-GR » 15 May 2012, 08:54

What I do, and probably the easiest way, and no need to change any files...
1) turn on "Use Flash Master Socket Policy" in the "Adobe Flash Player" in Server Configurator
2) listen on port 843 TCP, and UDP if you are going to use that
3) profit!

I think you can still use PrefetchPolicy on port 9933 from within Unity, and not have to make any changes.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Re: Unable to connect, as no valid crossdomain policy was fo

Postby ThomasLund » 17 May 2012, 15:03

Yeah - this code does the trick inside Unity before doing ANY networking. The timeout value of 500 allows the system to send you the file with a little delay. Found that needed sometimes:

Code: Select all

if (!Security.PrefetchSocketPolicy(serverName, serverPort, 500)) {
   Debug.LogError("Security Exception. Policy file load failed!");
}


Where serverName and serverPort are your usual SFS2X server address+port. Automagic works on port 9933.

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 30 guests