[Small Code Snippet] Local Hosting for Private Server Development

06/15/2012 07:05 Spirited#1
Hey everyone.

So previously, I was coming up with a few ideas on how to create a dynamic environment for development to simplify network communications (for demonstrations in random locations and such). I came up with a No-IP solution for public connections, but I don't always want my server to be public... so here's a local host solution:

Code:
// If the server is running on the local machine for development, get the 
// ip address that the machine would like to use:
#region Get Local Host
if (server.IPAddress == "localhost" || server.IPAddress.StartsWith("127"))
       foreach (NetworkInterface connection in NetworkInterface.GetAllNetworkInterfaces())
       {
             // If the connection is from the active network adapter, get the IPv4 
             // address of the connection:
             if (connection.OperationalStatus == OperationalStatus.Up)
             {
                   var properties = connection.GetIPProperties();
                   foreach (IPAddressInformation info in properties.UnicastAddresses)
                   {
                         // If the address is of type IPv4, that's the address we're looking for!
                         if (info.Address.AddressFamily == AddressFamily.InterNetwork && info.Address.ToString() != "127.0.0.1")
                         {
                               server.IPAddress = info.Address.ToString();
                               break;
                          }
                    }
             }
        }
#endregion
The only requirement is that your laptop must be connected to a gateway. Obviously, this is perfect for me because I my laptop is always in a location where it can be online. If this is a problem for you guys, use hamachi I guess.

Cheers.
- Spirited Fang
06/24/2012 21:25 koko20#2
Good Idea :D
06/25/2012 01:40 Spirited#3
Quote:
Originally Posted by koko20 View Post
Good Idea :D
I have a new thread about local hosting here:
[Only registered and activated users can see links. Click Here To Register...]

There are two different approaches to it in that thread discussed by me and Zeroxelli.