Skip to content

Mirror::Discovery::NetworkDiscovery

Inherits from NetworkDiscoveryBase< ServerRequest, ServerResponse >, MonoBehaviour

Public Functions

Name
virtual override void Start()
virtual so that inheriting classes' Start() can call base.Start() too

Protected Functions

Name
override ServerResponse ProcessRequest(ServerRequest request, IPEndPoint endpoint)
Process the request from a client
virtual override ServerRequest GetRequest()
Create a message that will be broadcasted on the network to discover servers
override void ProcessResponse(ServerResponse response, IPEndPoint endpoint)
Process the answer from a server

Public Properties

Name
long ServerId

Public Attributes

Name
Transport transport
ServerFoundUnityEvent OnServerFound

Additional inherited members

Public Functions inherited from NetworkDiscoveryBase< ServerRequest, ServerResponse >

Name
long RandomLong()
void AdvertiseServer()
Advertise this server in the local network
async Task ServerListenAsync()
void StartDiscovery()
Start Active Discovery
void StopDiscovery()
Stop Active Discovery
async Task ClientListenAsync()
Awaits for server response
void BroadcastDiscoveryRequest()
Sends discovery request from client

Protected Functions inherited from NetworkDiscoveryBase< ServerRequest, ServerResponse >

Name
virtual void ProcessClientRequest(Request request, IPEndPoint endpoint)
Reply to the client to inform it of this server

Public Properties inherited from NetworkDiscoveryBase< ServerRequest, ServerResponse >

Name
bool SupportedOnThisPlatform

Public Attributes inherited from NetworkDiscoveryBase< ServerRequest, ServerResponse >

Name
long secretHandshake

Protected Attributes inherited from NetworkDiscoveryBase< ServerRequest, ServerResponse >

Name
int serverBroadcastListenPort
UdpClient serverUdpClient
UdpClient clientUdpClient

Public Functions Documentation

function Start

inline virtual override void Start()

virtual so that inheriting classes' Start() can call base.Start() too

Reimplements: Mirror::Discovery::NetworkDiscoveryBase::Start

Protected Functions Documentation

function ProcessRequest

inline override ServerResponse ProcessRequest(
    ServerRequest request,
    IPEndPoint endpoint
)

Process the request from a client

Parameters:

  • request Request comming from client
  • endpoint Address of the client that sent the request

Return: The message to be sent back to the client or null

Override if you wish to provide more information to the clients such as the name of the host player

function GetRequest

virtual override ServerRequest GetRequest()

Create a message that will be broadcasted on the network to discover servers

Return: An instance of ServerRequest with data to be broadcasted

Reimplements: Mirror::Discovery::NetworkDiscoveryBase::GetRequest

Override if you wish to include additional data in the discovery message such as desired game mode, language, difficulty, etc...

function ProcessResponse

inline override void ProcessResponse(
    ServerResponse response,
    IPEndPoint endpoint
)

Process the answer from a server

Parameters:

  • response Response that came from the server
  • endpoint Address of the server that replied

A client receives a reply from a server, this method processes the reply and raises an event

Public Property Documentation

property ServerId

long ServerId;

Public Attributes Documentation

variable transport

Transport transport;

variable OnServerFound

ServerFoundUnityEvent OnServerFound;

Updated on 18 January 2021 at 03:17:53 UTC