Hi, guys. I'm making a game for a capstone project. It's a board game, that requires two human players to play over LAN. Since I am the only person on this project, I decided not to include singleplayer vs. AI (I might not finish it in time).
So, I researched up a way to have two players connect without relying on a database (I once considered using SQL Server, which would be a huge pain for the gamers), and found out about TCP / IP stuff that C# is capable of.
On the list of things I have yet to understand and do for myself, this is close to the top.
The very first thing I did was to have the host display it's IP Address, ala Diablo II, where the client must type in the host's IP address and press connect. I used the following code to retrieve the IP Address:
string myHost = System.Net.Dns.GetHostName();
string myIP = null;
for (int i = 0; i <= System.Net.Dns.GetHostEntry(myHost).AddressList.Length - 1; i++)
{
if (System.Net.Dns.GetHostEntry(myHost).AddressList[i].IsIPv6LinkLocal == false)
{
myIP = System.Net.Dns.GetHostEntry(myHost).AddressList[i].ToString();
}
}
txtIP.Text = myIP;
Which then returns a jumble of letters, numbers and in some cases, even signs. A far cry from the simple 192.168.XXX.XX I was expecting. I've researched in this, and know that it has something to do with the IPv4 or IPv6.
I've also seen somewhere that having a router might screw things up and IPv4 and IPv6 is OS dependent or something, which is horrible, because I'm using Windows 7, my test platform is Windows Vista, and my target client is Windows XP
Is there some way to retrieve that IP address?
In addition to the above, how does a client connect to the host using the host's IP Address?