Skip to content

Server Discoverer

The server discovery system helps clients find available servers to join. The server discoverer will return a ServerInfo for each of the servers found.

Password Check and Magic Number

The server owner can protect the game using a password, set in the NetworkTransport. When a client requests to join the server, the password must be provided (the transport should perform the verification, as the UDPNetworkTransport does).

The magic number is a unique number for each project, defined in NetworkManager.VersionMagicNumber. You can change it whenever you want to make a version incompatible with others. When a client requests to join the server, the magic number must be provided (the transport should perform the verification, as the UDPNetworkTransport does).

UDP Server Discoverer

The UDPServerDiscoverer is a class used to find all available servers across all your networks. This method will call a callback whenever it finds a new server, returning a UDPServerInfo containing the remote server's IP address along with the standard ServerInfo fields.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
var discoverer = new UDPServerDiscoverer(NetworkManager.Instance.versionMagicNumber, udp.port);
discoverer.Search((info) =>
{
    list.Add(info);
    _serverList = list.ToArray();
}, 
() => 
{ 
    Debug.Log("Done!");
});

//discoverer.Cancel();