Skip to content

Mirror::Discovery::NetworkDiscoveryBase

Base implementation for Network Discovery. Extend this component to provide custom discovery with game specific data NetworkDiscovery for a sample implementation More...

Inherits from MonoBehaviour

Public Functions

Name
long RandomLong()
virtual void Start()
virtual so that inheriting classes' Start() can call base.Start() too
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

Name
virtual void ProcessClientRequest(Request request, IPEndPoint endpoint)
Reply to the client to inform it of this server
virtual abstract Response ProcessRequest(Request request, IPEndPoint endpoint) =0
Process the request from a client
virtual Request GetRequest()
Create a message that will be broadcasted on the network to discover servers
virtual abstract void ProcessResponse(Response response, IPEndPoint endpoint) =0
Process the answer from a server

Public Properties

Name
bool SupportedOnThisPlatform

Public Attributes

Name
long secretHandshake

Protected Attributes

Name
int serverBroadcastListenPort
UdpClient serverUdpClient
UdpClient clientUdpClient

Detailed Description

template <Request ,
Response >
class Mirror::Discovery::NetworkDiscoveryBase;

Base implementation for Network Discovery. Extend this component to provide custom discovery with game specific data NetworkDiscovery for a sample implementation

Public Functions Documentation

function RandomLong

static inline long RandomLong()

function Start

inline virtual void Start()

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

Reimplemented by: Mirror::Discovery::NetworkDiscovery::Start

function AdvertiseServer

inline void AdvertiseServer()

Advertise this server in the local network

function ServerListenAsync

inline async Task ServerListenAsync()

function StartDiscovery

inline void StartDiscovery()

Start Active Discovery

function StopDiscovery

inline void StopDiscovery()

Stop Active Discovery

function ClientListenAsync

inline async Task ClientListenAsync()

Awaits for server response

Return: ClientListenAsync Task

function BroadcastDiscoveryRequest

inline void BroadcastDiscoveryRequest()

Sends discovery request from client

Protected Functions Documentation

function ProcessClientRequest

inline virtual void ProcessClientRequest(
    Request request,
    IPEndPoint endpoint
)

Reply to the client to inform it of this server

Parameters:

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

Override if you wish to ignore server requests based on custom criteria such as language, full server game mode or difficulty

function ProcessRequest

virtual abstract Response ProcessRequest(
    Request request,
    IPEndPoint endpoint
) =0

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 Request GetRequest()

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

Return: An instance of ServerRequest with data to be broadcasted

Reimplemented by: Mirror::Discovery::NetworkDiscovery::GetRequest

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

function ProcessResponse

virtual abstract void ProcessResponse(
    Response response,
    IPEndPoint endpoint
) =0

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 SupportedOnThisPlatform

static bool SupportedOnThisPlatform;

Public Attributes Documentation

variable secretHandshake

long secretHandshake;

Protected Attributes Documentation

variable serverBroadcastListenPort

int serverBroadcastListenPort = 47777;

variable serverUdpClient

UdpClient serverUdpClient;

variable clientUdpClient

UdpClient clientUdpClient;

Updated on 20 January 2021 at 18:58:27 UTC