Getting ip of dynamic dns hostname

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

Moderators: Lapo, Bax

jfullernz
Posts: 8
Joined: 20 Jul 2013, 11:43

Getting ip of dynamic dns hostname

Postby jfullernz » 22 Jul 2013, 14:05

Hi guys, first time poster here and hoping there is someone that can assist with an issue.
In summary, I am running the testing webhost on a non-static ip, and using a dyndns service to update the ip on change. My main issue arises with the crossdomain policy's retreival as that requires a ip rather than a hostname.
Currently using sfs2x 2.7 with unity3d 4.1.5f running under windows 7.
Apache and obviously sfs2x are installed and working, although there is no module for apache that will run on the windows version to allow socket policy so that is being handled by sfs.
What I am needing to find out is how I can resolve the hostname into a useable ip address for the PrefetchSocketPolicy(serverName, serverPort, timeout)?

I have tried using a hostname directly which just hangs indefinately after warning that policy file failed to load and no other warnings.
I have also tried using serverip=Dns.GetHostAddresses(hostname)[0].ToString(); but that just gives an infinate error after it stops smartFox from instantiating.

the code samples of the effected areas are below:

Code: Select all

if (Application.isWebPlayer || Application.isEditor) {
         
         //serverip=Dns.GetHostAddresses("http://devtest.servegame.com")[0].ToString();
         Debug.Log(serverip);
         if (!Security.PrefetchSocketPolicy(host, serverPort, 500)) {
            Debug.LogError("Security Exception. Policy file load failed!");
         }
      }      

      if (SmartFoxConnection.IsInitialized) {
         smartFox = SmartFoxConnection.Connection;
      } else {
         //Security.PrefetchSocketPolicy(serverName, serverPort);
         smartFox = new SmartFox(debug);
      }

not sure what other parts may assist for some help, but more than happy to post other sections if you let me know what would help. Otherwise, hopefully someone has an idea on how to work this?
I had searched up on it, and found a similar issue back last year, but the post didnt say how it got resolved, if it ever did.

Thanks in advance.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Getting ip of dynamic dns hostname

Postby Lapo » 24 Jul 2013, 08:02

Welcome,
Apache and obviously sfs2x are installed and working, although there is no module for apache that will run on the windows version to allow socket policy so that is being handled by sfs.

I don't understand this point. You don't need Apache to fetch the policy file, it will be done via socket from SFS2X.

What I am needing to find out is how I can resolve the hostname into a useable ip address for the PrefetchSocketPolicy(serverName, serverPort, timeout)?

This is not much of an API problem, so I think you should search for specific .Net/Mono resources.
Have you seen this for example?
http://stackoverflow.com/questions/1324 ... name-to-ip

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Getting ip of dynamic dns hostname

Postby Lapo » 24 Jul 2013, 08:04

I have also tried using serverip=Dns.GetHostAddresses(hostname)[0].ToString(); but that just gives an infinate error after it stops smartFox from instantiating.

What kind of errors do you get?
Have you verified what is actually returning the Dns.GetHostAddresses call?
Lapo

--

gotoAndPlay()

...addicted to flash games
SkaiCloud
Posts: 8
Joined: 01 May 2013, 04:20

Re: Getting ip of dynamic dns hostname

Postby SkaiCloud » 01 Aug 2013, 00:46

Hello I think this is what you are looking for. This snippet will check website URL for its IP address and it works for both dynamic and static ip no matter what your IP is it will always find the right location.

Code: Select all

using System.Net; //You will need this
 
public class NetworkConnection : MonoBehaviour {

   private string NetworkIP = "MyWebsite.com"; //Make sure you use this naming convention. Sometimes www or http will not work I have no clue. Stick to this format and it will work.
   private int NetworkPort = 9933;

   if(Application.isWebPlayer || Application.isEditor)
             {
             while(CheckSecurityPolicy() == false)
                {
                Debug.Log("Security Exception. Policy file load failed!");
                yield return new WaitForSeconds(5.0f); //Check again in 5 seconds.
                }   
             }

   bool CheckSecurityPolicy()
      {
         IPHostEntry host;

         host = Dns.GetHostEntry(NetworkIP); //Get Website IP address

         Debug.Log(host.AddressList[0].ToString()); //Making sure it is the right ip address because we use website URL

         // In a webplayer (or editor in webplayer mode) we need to setup security policy negotiation with the server first

         if (Security.PrefetchSocketPolicy(host.AddressList[0].ToString(), NetworkPort,500))
            return true;
         else
            return false;      
      }
}

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 21 guests