ServerDiscovery class
Allows to monitor publicly-listed running servers for server listing.
Runs on a background thread in one of two roles: when given a NetworkManager it advertises the local server, answering UDP multicast discovery requests on the LAN and publishing the server to the public list; when given an IServerObserver it sends discovery requests and downloads the public list, reporting each discovered server back to the observer.
Constructors, destructors, conversion operators
- ServerDiscovery(NetworkManager* server)
- Creates an instance to advertise a running local server.
- ServerDiscovery(IServerObserver* observer)
- Creates an instance to observe remote servers.
- ~ServerDiscovery()
Public functions
-
void SetStatusProvider(std::
weak_ptr<IServerStatusProvider> statusProvider) - Sets status provider.
- void Stop()
- Stops discovering and waits for the discovery thread to end.
- void RequestStop()
- Asks the discovery thread to end without waiting for it.
- auto HasFinished() const -> bool
- Whether the discovery thread has ended (also
truewhen it never ran).
Constants
-
static std::
uint16_t DiscoveryPort constexpr - UDP port for server discovery broadcast.
-
static std::
int32_t UniqueIdentifierLength constexpr - Length of server unique identifier.
Function documentation
void Jazz2:: Multiplayer:: ServerDiscovery:: Stop()
Stops discovering and waits for the discovery thread to end.
The destructor does the same; this is for a caller that has to release the thread earlier - the server list calls it right before connecting, because on the PSP the thread-stack pool cannot hold the discovery thread and the multiplayer client thread at the same time (see nCine::
void Jazz2:: Multiplayer:: ServerDiscovery:: RequestStop()
Asks the discovery thread to end without waiting for it.
For a caller that cannot afford the wait Stop() is - the thread can be seconds inside an access point association or a download - and polls HasFinished() instead, calling Stop() once it answers true (which is then instant). Nothing is discovered after this returns.