Master Server Connection

The master server holds the information about currently running room servers and the available rooms. The master server connection is stored as the masterSession member of the StrixNetwork instance.

Firstly, you need to make a connection to the master server in order to get information about room servers, such as their internet address, ports, etc., as well as information about available rooms.

The master server connection may be closed if no activities are observed for a while. However, once the master server connection has been established, the connection information is kept internally, and the master server connection is automatically restored as necessary.

When you are done using Strix Server, you can disconnect from the master server explicitly.

Connection

Before connecting, make sure that the applicationId property of the StrixNetwork singleton is set to the value specified by the server. Then, you call the ConnectMasterServer() method on the StrixNetwork singleton to make a connection, using the master server’s domain (host) name or IP address.

// Default port number
void ConnectMasterServer(string host, StrixNetworkConnectEventHandler connectEventHandler, StrixNetworkConnectFailedEventHandler errorEventHandler)

// User specified port number
void ConnectMasterServer(string host, int port, StrixNetworkConnectEventHandler connectEventHandler, StrixNetworkConnectFailedEventHandler errorEventHandler)

Note

When using Strix Cloud, the application ID is assigned by the Strix Cloud and shown on the Application Dashboard of your Strix Cloud application. Your master server’s domain name is also shown as Master Hostname on the dashboard.

Strix Cloud always use the default port number (see below), so you can use the first overload.

You should not specify an IP address when using Strix Cloud. The IP address may change during the operation of the server instance.

If you’re already connected, calling this method again with different host and port parameters will first close the existing connection before trying to open a new one.

After the connection has been made, you can use the master server session via the masterSession property on the StrixNetwork singleton if necessary.

URL-based connection

Beginning with Strix Unity SDK version 1.5.0, the first overload of ConnectMasterServer accepts a URL-style string in its host parameter as well as a raw IP address or a host domain name.

The syntax of the host string is as follows:

[protocol://]address[:port][/path]

where

  • Optional protocol is either tcp, udp, ws, or wss;

  • mandatory address is an IP address or a domain name;

  • optional port is a port number; and

  • optional path is a string specified by the server configuration.

The protocol in the URL-style string is as follows:

String

Description

(omitted)

The entire host string is an IP address or a domain name, i.e., port and path should also be omitted, and the platform’s default transport protocol is used.

tcp://

TCP is used for the transport.

udp://

Reliable UDP is used for the transport. (RUDP is not available on Strix Cloud.)

ws://

Regular WebSocket is used for the transport.

wss://

Secure WebSocket is used for the transport.

If port is omitted, the protocol’s default port number is assumed, which are as follows:

Protocol in use

Port number

TCP

9122

Reliable UDP

9122

Regular WebSocket (ws)

80

Secure WebSocket (wss)

443

Note

The default port number for a secure WebSocket URL is 443, but master servers on Strix Cloud always use the port 9122 even for WebSocket. You can’t omit the port number when using secure WebSocket on Strix Cloud.

When TCP or UDP is used, the path is ignored.

When a WebSocket protocol is used, the path is sent to the server as a part of its connection handshake. If the path is omitted, it is assumed "/". The path should match with the path the server expects. When using Strix Cloud, the server always expects "/", so you should omit it in the host string.

Examples:

  • "000000000000000000000000.game.strixcloud.net": TCP connection to the server whose domain name is 000000000000000000000000.game.strixcloud.net with port 9122.

  • "tcp://198.51.100.2:8888": TCP connection to the server at 198.51.100.2 with port 8888.

  • "wss://000000000000000000000000.game.strixcloud.net:9122": Secure WebSocket connection to the server whose domain name is 000000000000000000000000.game.strixcloud.net with port 9122 using an empty path.

Note

The WebSocket protocols (either regular or secure) are intended for use on the WebGL platforms. They have more overheads in CPU usage and network traffic when compared to TCP. It is not recommended to use a WebSocket transport unless you target WebGL platforms or you want a cross-platform matchmaking with WebGL platforms.

See How to Create an HTML5 and WebGL Client for more on WebGL support.

Strix Cloud supports TCP and secure WebSocket (wss) as transports. Reliable UDP and regular WebSocket (ws) are not available.

Disconnection

The master server can be explicitly disconnected with the DisconnectMasterServer() method on the StrixNetwork.

void DisconnectMasterServer()

After the explicit disconnection, the connection information that was kept internally is discarded, and all functions that operate on the master server will fail. Typically, disconnecting the master server will take place when leaving the multiplayer context of a game and ending networked functionality.

Status

The status of the master server connection is stored in the IsConnected value on the StrixNetwork.masterSession.

bool isConnected = StrixNetwork.instance.masterSession.IsConnected;

The master server connection is not always active; the SDK monitors its activities and closes the connection by a timeout to save resources. However, the connection information specified to ConnectMasterServer is kept internally, and the connection will be restored automatically when the master server connection is required again. The process is transparent to the user codes, and you don’t need to care about it.

The masterSession.IsConnected indicates the actual connection status, meaning it returns false after the master server connection has been closed for an inactivity. You usually don’t need to care about the IsConnected status, either.