I'm using the ExampleMenu.cs as template for all my network functionality. Of course some things must be changed and I don't know how, like the following:
- After calling TNServerInstance.Start(serverTcpPort, udpPort, "server.dat", lobbyPort), and after TNServerInstance.isActive returns true, I want to automaticaly connect to the local server that was just created but I don't know what address to use.
Also, I would generaly need a way to allways know the IP address when pausing the game for instance, so other players can connect manually to that address.
I currently use this which works fine on everything except iOS:
try
{
string sHostName = System.Net.Dns.GetHostName();
System.Net.IPHostEntry ipE = System.Net.Dns.GetHostEntry(sHostName);
System.Net.IPAddress[] IpA = ipE.AddressList;
labelIP.text = "Your I.P.: " + IpA[0].ToString();
}
catch (System.Exception e)
{
Debug.LogWarning("tried to read IP but smth failed " + e.Message);
labelIP.text = "Offline";
}
I'm sure there's a better and safer way to get the IP (Unity/Tnet wrapper functions) address regardless of the device or OS.