Browsing available servers

To browse the available servers, call MasterServer.RequestHostList. This takes one single parameter: the game type name (this is the same game type name you passed to RegisterHost).

This does not return anything, instead the result will be asynchronously downloaded, and the last known list of servers can be accessed via MasterServer.PollHostList. Additionally, to ensure you aren't using old data, you can call MasterServer.ClearHostList. For example, if the user hits the Refresh button in the lobby you might clear the host list and then request a new list from the Master Server.

The following script shows a lobby for users to browse available servers and connect to them:

using UnityEngine; using System.Collections; public ...

Get Unity Multiplayer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.