Connect() failed: System.Security.SecurityException: Unable

Options
amiractivate
edited June 2012 in Photon Server
First of all I am aware of these thread :
viewtopic.php?f=6&t=1033
viewtopic.php?f=5&t=1757&start=10

But first let me explain my situation:

Runs the game within the same network as the server -> everything OK
Runs the game from outside of the network ->
1) from a Unity3d editor -> initial login/connect/create room (which requires the policy) OK but later on after I leave a room the error comes out.
2) from a browser through client hosted on a pc within the same network as the server - > no debugging enabled but it hangs exactly like 1)

so based on the above im guessing its not the same as viewtopic.php?f=6&t=1033 because I managed to connect and create rooms in the 1st place, only the disconnect/autoconnect to the master fails

also based on the above i dont think its the same as viewtopic.php?f=5&t=1757&start=10 because Im facing the problem even with the editor

the error mentioned above:

Connect() failed: System.Security.SecurityException: 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 ExitGames.Client.Photon.NConnect.StartConnection () [0x00000] in <filename unknown>:0
UnityEngine.Debug:LogError(Object)
PhotonHandler:DebugReturn(DebugLevel, String) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:115)
NetworkingPeer:DebugReturn(DebugLevel, String) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:700)
ExitGames.Client.Photon.NConnect:StartConnection()
ExitGames.Client.Photon.EnetPeer:Connect(String, String, Byte)
ExitGames.Client.Photon.PhotonPeer:Connect(String, String, Byte)
NetworkingPeer:Connect(String, String, Byte) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:169)
PhotonNetwork:Connect(String, Int32, String, String) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:600)
PhotonNetwork:Connect(String, Int32, String) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:555)
<ConnectToServer>c__Iterator7:MoveNext() (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Amir/Scripts/StuckoGameFrameWork/GameController.cs:411)

followed by :
Received unknown status code: SecurityExceptionOnConnect
UnityEngine.Debug:LogError(Object)
PhotonHandler:DebugReturn(DebugLevel, String) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:115)
NetworkingPeer:DebugReturn(DebugLevel, String) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:700)
NetworkingPeer:OnStatusChanged(StatusCode) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1072)
ExitGames.Client.Photon.NConnect:StartConnection()
ExitGames.Client.Photon.EnetPeer:Connect(String, String, Byte)
ExitGames.Client.Photon.PhotonPeer:Connect(String, String, Byte)
NetworkingPeer:Connect(String, String, Byte) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:169)
PhotonNetwork:Connect(String, Int32, String, String) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:600)
PhotonNetwork:Connect(String, Int32, String) (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:555)
<ConnectToServer>c__Iterator7:MoveNext() (at C:/Users/Amir/Activate/01 KLKK/02 Source/SVNKLKK/Assets/Amir/Scripts/StuckoGameFrameWork/GameController.cs:411)

Would be great if someone can help analyze this and perhaps pinpoint the possible cause of this error.

Thanks :)

Comments

  • Tobias
    Options
    I just created a small PolicyChecker. Use it to check the availability of the policy-request port.

    If you set the Editor to build for WebPlayer, the resulting WebPlayer build AND the Editor (yes, either) will do policy requests. You don't have to prefetch anything, this is done by Unity on the default port 843. Photon is by default setup to answer on this port with the cross domain policy.

    There are 4 steps that could lead to failing policy requests:
    1: Photon and or Policy app is not running
    2: Firewall is not open for TCP 843 (no matter if Windows Firewall, hardware firewall, router or any other)
    3: Router does not forward incoming requests on TCP 843 to the machine that runs Photon
    4: IP or Host-address not available for your clients

    First, check locally, then from another machine in the same network, then from the internet.
  • Hi Tobias,

    Thanks for the Policy Checker.

    Ive tried the policy checker targetting the port im using for the policy application 843: From PC within the same network and From PC outside of the network :

    Tested host: XXX.XXX.XXX.XXX port:843
    Connected and got some answer. Check opened ports in content.

    <cross-domain-policy>
    <allow-access-from domain="*" to-ports="5055,5056,5057,4530,4531,4532,90
    90" />
    </cross-domain-policy>

    I didnt try it on the server as I dont have .net 4.X framework installed (required by ur policy checker)

    Im guessing these are fine?

    I did some further testing with other pc outside of the network and suprisingly some did not encounter this problem. The difference between the ones that encountered the problem and the ones that did not is the connection type used:

    1) The ones that got the error = using cabled connection obtained via a router (tested from 2 computers, 1 from outside of the country, one from within the country)
    2) The ones that didnt get the error = using a wireless connection dongle provided by our ISP (I tested on 2 computers using the sane dongle)

    also ive looked at the log files from the server and noticed something unusual :

    From the GameServer logs:

    2012-06-21 15:57:47,178 [9] INFO Photon.LoadBalancing.GameServer.OutgoingMasterServerPeer [(null)] - Successfully registered at master server: serverId=2ae8ae23-f1cc-45d8-ace2-3a8cc464f0ff
    2012-06-21 15:57:55,056 [10] ERROR Photon.LoadBalancing.LoadShedding.WorkloadController [(null)] - Latency monitor connection to XXX.XXX.XXX.XXX:4531 failed with err 121: The semaphore timeout period has expired., serverId=2ae8ae23-f1cc-45d8-ace2-3a8cc464f0ff
    2012-06-21 15:58:00,282 [10] ERROR Photon.LoadBalancing.LoadShedding.WorkloadController [(null)] - Latency monitor connection to XXX.XXX.XXX.XXX:5056 failed with err 258: The wait operation timed out., serverId=2ae8ae23-f1cc-45d8-ace2-3a8cc464f0ff
    2012-06-21 15:58:02,185 [9] INFO Photon.LoadBalancing.GameServer.OutgoingMasterServerPeer [(null)] - connection to master closed (id=803, reason=ClientDisconnect, detail=), serverId=2ae8ae23-f1cc-45d8-ace2-3a8cc464f0ff
    2012-06-21 15:58:17,099 [10] ERROR Photon.LoadBalancing.LoadShedding.WorkloadController [(null)] - Latency monitor connection to XXX.XXX.XXX.XXX:4531 failed with err 121: The semaphore timeout period has expired., serverId=2ae8ae23-f1cc-45d8-ace2-3a8cc464f0ff
    2012-06-21 15:58:17,193 [6] INFO Photon.LoadBalancing.GameServer.GameApplication [(null)] - Reconnecting to master at 127.0.0.1:4520, serverId=2ae8ae23-f1cc-45d8-ace2-3a8cc464f0ff

    *this runs continuously even with no connection attempts

    From the MasterServer logs:

    2012-06-21 16:01:17,419 [10] DEBUG Photon.LoadBalancing.MasterServer.MasterApplication [(null)] - Received init request from game server
    2012-06-21 16:01:17,419 [10] INFO Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer [(null)] - game server connection from 127.0.0.1:52550 established (id=355)
    2012-06-21 16:01:17,419 [8] DEBUG Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer [(null)] - OnOperationRequest: pid=355, op=1
    2012-06-21 16:01:17,435 [8] DEBUG Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer [(null)] - Received register request: Address=XXX.XXX.XXX.XXX, UdpPort=5056, TcpPort=4531, WebSocketPort=0, State=Normal
    2012-06-21 16:01:17,435 [8] DEBUG Photon.LoadBalancing.LoadBalancer`1 [(null)] - new min server is GameServer(2ae8ae23-f1cc-45d8-ace2-3a8cc464f0ff) at XXX.XXX.XXX.XXX:4531/XXX.XXX.XXX.XXX:5056 with load 0 - old one had load
    2012-06-21 16:01:17,435 [8] INFO Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer [(null)] - OnDisconnect: game server connection closed (connectionId=354, serverId=cd9042f8-b1f0-4dca-b512-ee51bc28fcc6, reason=ManagedDisconnect)
    2012-06-21 16:01:18,449 [9] DEBUG Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer [(null)] - UpdateGameServer - from LoadLevel Lowest to Normal, PeerCount 1
    2012-06-21 16:01:18,449 [9] DEBUG Photon.LoadBalancing.LoadBalancer`1 [(null)] - updated current min load to 2
    2012-06-21 16:01:32,442 [10] DEBUG Photon.LoadBalancing.MasterServer.MasterApplication [(null)] - Received init request from game server
    2012-06-21 16:01:32,442 [10] INFO Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer [(null)] - game server connection from 127.0.0.1:52551 established (id=356)
    2012-06-21 16:01:32,442 [6] DEBUG Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer [(null)] - OnOperationRequest: pid=356, op=1
    2012-06-21 16:01:32,442 [6] DEBUG Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer [(null)] - Received register request: Address=XXX.XXX.XXX.XXX, UdpPort=5056, TcpPort=4531, WebSocketPort=0, State=Normal
    2012-06-21 16:01:32,442 [6] DEBUG Photon.LoadBalancing.LoadBalancer`1 [(null)] - new min server is GameServer(cd9042f8-b1f0-4dca-b512-ee51bc28fcc6) at XXX.XXX.XXX.XXX:4531/XXX.XXX.XXX.XXX:5056 with load 0 - old one had load
    2012-06-21 16:01:32,442 [6] INFO Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer [(null)] - OnDisconnect: game server connection closed (connectionId=355, serverId=2ae8ae23-f1cc-45d8-ace2-3a8cc464f0ff, reason=ManagedDisconnect)
    2012-06-21 16:01:33,472 [9] DEBUG Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer [(null)] - UpdateGameServer - from LoadLevel Lowest to Normal, PeerCount 1
    2012-06-21 16:01:33,472 [9] DEBUG Photon.LoadBalancing.LoadBalancer`1 [(null)] - updated current min load to 2


    *this also runs continuously

    I was thinking that maybe my settings are wrong, the only thing I remember changing are these lines (in the GameServer1 and GameServer 2:
    <setting name="PublicIPAddress" serializeAs="String">
    <value>XXX.XXX.XXX.XXX</value>

    *The value was changed from 127.0.0.1 to the server's public IP.


    The other thing that seems unusual is that during the initial connection to the server and creation -> joining of the room, no errors are thrown from unity. however when I disconnect from the room, the 2 errors from the 1st post appear. From what I understand from your previous post, when I disconnect from a room, the client will be automatically request connection to the master server/lobby am I right? It seems that this second time tryring to log into the master server is throwing the error. And as explained above, not all computers I try to connect to have this problem.


    From the potenial reasons of failling policy request :
    1: Photon and or Policy app is not running -> can be ruled out in my case right? since ive checked its running according to the logs and I managed to connect and create room the 1st time.
    2: Firewall is not open for TCP 843 (no matter if Windows Firewall, hardware firewall, router or any other) -> im not sure as im no network expert, but his happens even when I closed down the firewalls on the server.
    3: Router does not forward incoming requests on TCP 843 to the machine that runs Photon -> For this server we are set it up as a Virtual Computer assigning a public IP address to the network IP address.
    4: IP or Host-address not available for your clients ->Not sure how to test this, but as stated above I managed to connect and create room the 1st time, only when logging out of a room that this error pops up.


    Sorry for the long post but I hope you guys can have a better understanding of my setup and issue.
  • Tobias
    Options
    1) The ones that got the error = using cabled connection obtained via a router (tested from 2 computers, 1 from outside of the country, one from within the country)

    That's funny. Are you sure your server is setup with a public IP then? It seems that clients within your ISPs network get connection, the others don't?
    Visit whatismyip.com from the machine that hosts Photon and compare the shown IP with the one setup in the gameserver config.

    I asked a colleague to check your server log posting. They will know what the error means.
  • Yeah im pretty sure its set up to be accessible from the public IP. And just because my scenario does sound weird I rechecked and result is the ip is the same as the one im using for the host.

    Actually all the different computers ive tested can connect to the server and create rooms /join (play the game partially)

    Its just that when I disconnect (from the room to be in a scene for just that 1 player) that I get weird behaviors ( haha and yes its weird that I still retest them to just to be certain)

    Had no problem disconnecting
    1) Within same network
    2) Using the pc from 1), disconnected lan cables then used a dongle Different ISP (wireless connection)

    These had problems when disconneting
    3) Within same ISP (cabled via router)
    4) Using the pc from 3), disconnected lan cables then used a dongle Different ISP (wireless connection)
    5) Different country / ISP (I have to ask my collegue tommorow the kind of setup they have there)

    * Im going to make more tests on different setups. Will post once I get the result.
  • Hi Tobias,

    Weve managed to sort of figure out the cause of the errors. I made a new setup in a different server (a hosted solution server). Everything works fine now.

    Apparently using the server as a virtual computer was the cause. Maybe theres some additional settings that needs to be done in order to make it work.

    Anyways, I wont be working on that server for a while.

    Again Thanks for the help
  • Tobias
    Options
    Good to read you found a workaround and have no problems on a non-virtual machine.
    Which VM was running your previous server?

    The VMs are maybe behaving like their own firewall or might be less suited to forward socket requests. No idea. We would need to investigate with the help of Wireshark who is sending what and where something fails to get delivered.
  • Hi Tobias,

    The virtual computer setting we are using is not virtual machine. We were using a physical computer as the server but using a feature of a router called virtual computer. I dont really know how it work but here is a screenshot and the link to the manual.

    http://download.level1.tw/level1/manual ... M_V1.0.pdf

    apart from that , we actually found another problem, I thought I was all solved when we moved server but apparently I still get some errors regarding policy when using the browser. Its fine now with editors/standalone. Im pretty sure I read somewere in the forum about it but maybe the issue was different.

    I checked the unitywebplayer log files and found this :

    SocketPolicyClient14: Incoming GetPolicyStreamForIP

    SocketPolicyClient14: About to BeginConnect to 127.0.0.1:843

    SocketPolicyClient14: About to WaitOne

    SocketPolicyClient14: Caught exception: No connection could be made because the target machine actively refused it.


    whats weird is that the BeginConnect is trying to connect to 127.0.01:843, im pretty sure thats why I couldnt get the policy. But where/ how do I change that to the server where im hosting photon? And this only happens when I disconnect/leave room, is that intended? retrieving policy when a user disconnects? because I could create and join rooms earlier on.
  • Tobias
    Options
    When you leave a room in a loadbalanced setup, you also disconnect from the specific game server and re-connect to the master.
    Please read again the help we provided. I am out of ideas, really and think you missed something.

    It's not useful to change the default policy port.
    It's no use to prefetch the socket policy file by your own code in Unity.
    The Unity Editor will fetch the policy file like the Webplayer does, when you set Webplayer as build setting. Not when setup for standalone.
    Ports must be opened in firewalls and forwarded by routers.
    Your actual, public IP is different from your internal (behind the router) IP. Get the right IPs.

    We can't support your Virtual Computer feature. This is something you will have to ask your router's manufacturer about!
  • Hi Tobias,

    Regarding the virtual computer feature, thank you for the clarification. We wont be using that to implement Photon Server then.

    Regarding the policy request issue:

    It's not useful to change the default policy port. -> did not change it, still is 843
    It's no use to prefetch the socket policy file by your own code in Unity. -> not prefetching, using PUN
    The Unity Editor will fetch the policy file like the Webplayer does, when you set Webplayer as build setting. Not when setup for standalone. -> Running Editor set as Webplayer - Fine, Running via browser - problem
    Ports must be opened in firewalls and forwarded by routers. -> server hosted on hosting site - I am told that request for all ports are forwarded, turned off the server firewalls when testing
    Your actual, public IP is different from your internal (behind the router) IP. Get the right IPs. -> pretty sure im using a public ip, else I cant even access it from outside

    Im doing as you advise, seeing if I missed anything or something wrong with the code im using. but FYI

    I managed to connect to the server and I was able to create a room and joined it. (I assume the policy is needed to connect connect/create rooms ) . Meaning I got the policy the 1st time around but failed the second time around. And looking at the webplayerlog :

    SocketPolicyClient14: About to BeginConnect to 127.0.0.1:843

    explains why it couldnt get the policy.

    remember I posted earlier that some computers from within the network could access while the outside one had problem. Double checked it and apparently it has nothing to do ISP/inside/outside. The ones that had no problem had photonserver installed on them and it stopped working when I turned off the photonserver. From the above log, now things are making sense, its because the game is trying to get the policy at 127.0.0.1 and I happen to have photon server on on 127.0.0.1.

    My only question now is why is it trying to get the policy at 127.0.0.1, and from what I understand this is done by UnityWebPlayer, hence I guess everything is fine on the server side (photon) and I should be looking at client side.

    anyways thanks again Tobias, ill probably bug the unity guys now. Ill post the fix/explaination of why it happened when I do find out.
  • Tobias
    Options
    Is your loadbalancing server setup correct? You have to edit it for the gameservers, so they know their correct, public ip.
    viewtopic.php?f=17&t=1102&p=5470&hilit=LoadBalancing.dll.config#p5470