How to use the Security.PrefetchSocketPolicy !!!!

Discussion in 'Multiplayer Networking' started by josszp, Jun 21, 2012.

  1. josszp

    josszp

    Member

    Joined:
    Jul 15, 2010
    Messages:
    13
    I am confused with Security.PrefetchSocketPolicy call. Headachy some really!!

    1. Only the Web Player is Evil some:
    I use the photon as my game server which has its policy server on default port 843.
    Then I connect to the server(use socket, you known). Everything works properly in Editor and StandAlone but the WebPlayer.
    2. The IP and Port is OK
    I am sure my fireworks not block the port 843, I turn them off. I can telnet the port and get the crossdomain string back successfully. either to the sockpol Server(offer by unity) or Photon policy server. All port and IP works perfectly except in Webplayer!
    3.I do myself, but not work
    The doucument from the Unity tell me I needn't call the Security.PrefetchSocketPolicy("172.16.0.111", 843, 300), eveything default will work for me. But in act it doesn't.
    OK, no problem, I did it myself with the following code:
    void Awake()
    {
    if (Global.Instance !Global.Instance.Offline)
    {
    PhotonNetwork.Init();
    Debug.Log("fffffffffffffffffffffffffffffffffffffffffffff1");
    if (!Security.PrefetchSocketPolicy("172.16.0.111", 843, 300))
    {
    Debug.LogError("PrefetchSocketPolicy failed!");
    }
    else
    {
    Debug.LogError("PrefetchSocketPolicy OK!");
    }
    Debug.Log("fffffffffffffffffffffffffffffffffffffffffffff2");
    PhotonNetwork.ConnectUsingSettings("0.1");
    }
    }
    4. I try to change the port to 2018, this time is more strange, It doesn't work even in Editor
    I change code to: if (!Security.PrefetchSocketPolicy("172.16.0.111", 2018, 300)) and change the photon policy listener port to 2018

    I mean if I can call Security.PrefetchSocketPolicy("172.16.0.111", 843, 300) successfully, everything will be ok! But I never, never got the successful return. It is always print "PrefetchSocketPolicy failed!"

    Pool man, I've work around it for 5 days, I test it , I try all suggestion from the warmhearted friends (etc: Tobias,). but it still stay there. The evil webplayer!!!!
    Help me Pls. guy?
    How can I me the Security.PrefetchSocketPolicy work in webplayer???????
     
  2. tcarr9

    tcarr9

    New Member

    Joined:
    Oct 11, 2010
    Messages:
    63
    What's the third parameter? I use this when I hit ElectroServer and it works just fine, although I never examine the value it returns:
    Code (csharp):
    1.  
    2.                 #if UNITY_WEBPLAYER
    3.                 Security.PrefetchSocketPolicy(ip, Convert.ToInt32(serverPort));
    4.                 #endif
    5.  
    Perhaps the problem is with your crossdomain? What are you delivering?
     
  3. josszp

    josszp

    Member

    Joined:
    Jul 15, 2010
    Messages:
    13
    The third parameter is timeout is ms. I pass it as 300, 5000 or don't pass anything just like you. They don't work too.

    crossdomain string is OK, because I never change it. I am sure the policy request is not send or blocked. Because I debug the policy server, the server can't receive the request. When I connect use telnet IP 843 or run my game in Editor, the server can receive the request.

    But in webplayer, It won't send even if I add the code such as : Security.PrefetchSocketPolicy(ip, Convert.ToInt32(serverPort));
    Why!!!!!!!!!!!!!!!!!
     
  4. Tomo Games

    Tomo Games

    Member

    Joined:
    Sep 20, 2010
    Messages:
    217
    I wrote a post that may help you.
     
  5. josszp

    josszp

    Member

    Joined:
    Jul 15, 2010
    Messages:
    13
    Yeah, I have read you post for 4 times. But it all about policy request failed in Editor. But my state is : Everything works properly but web player!
    Only the web player.
    I try use the default port 843 or custom port:2048. Both failed!!
     
  6. josszp

    josszp

    Member

    Joined:
    Jul 15, 2010
    Messages:
    13
    Help me pls! Am I the only one met such a problem????
    Maybe I don't explain my problem clear. So I attach my link about the same problem here:
    http://forum.exitgames.com/viewtopic.php?f=5&t=1757&p=8458#p8458

    You know, I am really need you help now. For my game could publish to the tester, just for this evil problem!!!!!!
     
  7. josszp

    josszp

    Member

    Joined:
    Jul 15, 2010
    Messages:
    13
    Nobody can help me??????????
     
  8. Tomo Games

    Tomo Games

    Member

    Joined:
    Sep 20, 2010
    Messages:
    217
    Hi josszp

    Of course it would fail for your Web Player. The whole point of having the secure socket policy server is to prevent WEB PLAYER clients from accessing sites that shouldn't be accessible by users outside their intranet. So the cross domain files says I will allow this address on this port to be accessed by the web player. The Policy Server should run on the same box (same address) of the Game Server that is doing the hosting. The web player expects the policy server to be running on port 843. Unix machines would give you grief about reserved ports lower than 1024 as this needs to be run as root (not a problem for Windows). So Security.PrefetchSocketPolicy allows you to change the default setting to something higher than 1024 like 2048. But your photon policy server needs to actually run on 2048 or whatever secure socket policy server you have in place (like secpol.cs). The cross domain file would then name the actual game server port / range for connecting to your game server. Your game server port would not run on 2048 which is being occupied by the policy server...

    You may face another problem... Your Server Name look up may return more than one ip addresses. This code gets around that issue.
    Code (csharp):
    1.  
    2.     public string ipAddress = "www.mycomputer.com"; //"localhost";
    3.     public int gamePort = 14248;
    4.     public int policyPort = 8843;
    5.  
    6. public void OnGUI()
    7.     {
    8.         GUI.Label(new Rect(30, 255, 230, 40), "Server\nIP Address: ");
    9.  
    10.         ipAddress = GUI.TextField(new Rect(110, 270, 170, 22), ipAddress);
    11.  
    12.         if (GUI.Button(new Rect(20, 300, 260, 30), "Play Multi Player"))
    13.         {
    14.            
    15. # if UNITY_WEBPLAYER
    16.             bool isPolicyConnected = false;
    17.             string hostname = gm.ipAddress;
    18.             IPAddress[] ips = Dns.GetHostAddresses(ipAddress);
    19.             foreach (IPAddress ip in ips)
    20.             {
    21.                 ipAddress = ip.ToString();
    22.                 if (!(isPolicyConnected=Security.PrefetchSocketPolicy(ipAddress, policyPort, 5000)))
    23.                     print("policy socket address failed to connect to "+ipAddress+":"+policyPort);
    24.                 else break;
    25.             }
    26.             if(isPolicyConnected)
    27.                 Application.LoadLevel("mainscene");
    28.             else ipAddress=hostname;
    29. # else
    30.             Application.LoadLevel("mainscene");
    31. #endif
    32.         }
    33. }
    34.  
     
  9. josszp

    josszp

    Member

    Joined:
    Jul 15, 2010
    Messages:
    13
    God save me! Yeah!!!
    I am so excited, almost bacchanal some!! Just for getting rid of the Web player policy EVIL. Good bye, Mr Evil!!! Aha!
    So I am here, to tell the solution for the pool guy meets the same evil like me. I trace it for two weeks long. I means it is a period of hard time. It shouldn't be headache to you guys any more.
    Very simple reason. In my scene there is dlls (I18N.dll, I18N.CLK.dll), these two dll is used to support the Simple Chinese Input in Unity version 2.6(in version3.0 up, we needn't them. ). the version of them is older some. They cause some crash we can't print, but they make my browser cant parse the policy request. So the on the server side, policy server never gets any request.
    That's it!
    Evil's gone!!! The god sun's up!!!
    Thanks for the guys reply the post!!!
     
  10. zezba9000

    zezba9000

    Member

    Joined:
    Sep 28, 2010
    Messages:
    433
    SO what did you do to fix the problem?? Where do I stick these missing libs so the web player can use them?