Click or drag to resize

StrixNetworkConnectMasterServer Method (String, Int32, StrixNetworkConnectEventHandler, StrixNetworkConnectFailedEventHandler)

Establishes a connection with a master server.

Namespace:  SoftGear.Strix.Unity.Runtime
Assembly:  StrixUnityRuntime (in StrixUnityRuntime.dll) Version: 1.5.0
Syntax
C#
public void ConnectMasterServer(
	string host,
	int port,
	StrixNetworkConnectEventHandler connectEventHandler,
	StrixNetworkConnectFailedEventHandler errorEventHandler
)

Parameters

host
Type: SystemString
The address of the master server. Can be either URL, IPv4 address, or IPv6 address.
port
Type: SystemInt32
The port number of the master server. Must be between 1 and 65535. Default value for the Strix cloud is 9122.
connectEventHandler
Type: SoftGear.Strix.Unity.Runtime.EventStrixNetworkConnectEventHandler
This callback is invoked when the connection to the master server has been established successfully.
errorEventHandler
Type: SoftGear.Strix.Unity.Runtime.EventStrixNetworkConnectFailedEventHandler
This callback is invoked in case the connection could not be established.
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionThrown if port does not lie within 0-65535 range.
Remarks
Before calling this method you should set applicationId. It can be found on the Information tab of the Dashboard on the Strix Cloud web page. If already connected, calling this method with different host and/or port will close the existing connection before opening a new one.

Possible exception types in StrixNetworkConnectFailedEventArgs's cause:
ErrorCodeException Strix error which can be further separated by an error code:
ConnectionErrorFailed to send the request because of a connection error.
InvalidCredentialsType Credentials type does not match the server authentication configuration. This can happen if, for example, the server is configured to authenticate by password instead of application ID. On Strix Cloud this error should never occur since currently it always uses application ID authentication.
InternalError Internal server error. This can be caused by a bug or some other problem on the server and should be reported to the developers.
UnsupportedLibraryVersion Current client library is not supported by the server. This can happen if the client version is too old. To fix this error, update the Strix SDK to the latest version.
InvalidApplicationIdToken Application ID token provided via applicationId does not match the one on the server. Check if the application ID is the same as the one listed on Information tab of the Dashboard on the Strix Cloud web page.
SocketExceptionAn error occurred when attempting to access the socket.
WebException There has been an error when connecting to the authentication server.
It's either an HTTP error such as 404/Not Found, or a network error like failure to resolve a DNS entry, a socket error, etc.
ArgumentException When using an authentication server this error can happen if the server returns an invalid authorization token.
It could be an invalid UTF-8 string or an invalid JSON.
Exception This can happen if the address for the given host couldn't be resolved when establishing socket connection.
Examples
Note: Make sure to change the placeholder values of applicationId and host to the real ones that can be found on the Strix Cloud application information tab.
using SoftGear.Strix.Unity.Runtime;
using UnityEngine;

public class StrixConnectExample : MonoBehaviour
{
    void Start()
    {
        var strixNetwork = StrixNetwork.instance;

        strixNetwork.applicationId = "00000000-0000-0000-0000-000000000000";
        strixNetwork.ConnectMasterServer(
            host: "0123456789abcdef01234567.game.strixcloud.net",
            port: 9122,
            connectEventHandler: _ => Debug.Log("Connection established."),
            errorEventHandler: args => Debug.Log("Connection failed. " + args.cause?.Message));

        Debug.Log("Connecting to the master server...");
    }
}
See Also