Skip to main content

ServerUtilities

A class in Root.Township, the global namespace.

Static network helpers: public and local IP lookup, IPv4 validation, ping and the developers' LAN shortcuts.

Constructors​

MemberWhat it is
ServerUtilities()Creates a ServerUtilities with default values.

Fields​

MemberWhat it is
const float PingTimeoutSeconds before a ping gives up (5).
2 private and internal fields
MemberWhat it is
private static Logger loggerNLog logger for this class.
private static IPAddress publicIpAddressCached public IP from GetPublicIPAddress.

Methods​

MemberWhat it is
static string GetIpAddress(string serverIp)Expands shortcuts like local or a developer's name or initial, or a number under 10, to a LAN IP. Other strings come back unchanged.
static IPAddress GetLocalIPv4()Returns this machine's first IPv4 address, or IPAddress.None on failure.
IEnumerator GetPing(string ipAddress, Action<int> pingReceivedCallback) (iterator)Coroutine that pings an address for 5 seconds, calling back with the time every frame once done, then with -1 at the end.
static async Task<IPAddress> GetPublicIPAddress()Asks the Alta API for this machine's public IP once and caches it; 0.0.0.0 if the call fails.
static bool ValidateIPv4(string ipString)True when the string is four dot-separated numbers from 0 to 255.