/// Initialize a client for GameLift Realtime and connect to a player session.
    /// <param name="endpoint">The DNS name that is assigned to Realtime server</param>
    /// <param name="remoteTcpPort">A TCP port for the Realtime server</param>
    /// <param name="listeningUdpPort">A local port for listening to UDP traffic</param>
    /// <param name="connectionType">Type of connection to establish between client and the Realtime server</param>
    /// <param name="playerSessionId">The player session ID that is assigned to the game client for a game session </param>
    /// <param name="connectionPayload">Developer-defined data to be used during client connection, such as for player authentication</param>
    public RealTimeClient(string endpoint, int remoteTcpPort, int listeningUdpPort, ConnectionType connectionType,
                          string playerSessionId, byte[] connectionPayload)
    {
        // Create a client configuration to specify a secure or unsecure connection type
        // Best practice is to set up a secure connection using the connection type RT_OVER_WSS_DTLS_TLS12.
        ClientConfiguration clientConfiguration = new ClientConfiguration()
        {
            // C# notation to set the field ConnectionType in the new instance of ClientConfiguration
            ConnectionType = connectionType
        };

        // Create a Realtime client with the client configuration
        Client = new Client(clientConfiguration);

        // Initialize event handlers for the Realtime client
        Client.ConnectionOpen  += new EventHandler(OnOpenEvent);
        Client.ConnectionClose += new EventHandler(OnCloseEvent);
        Client.DataReceived    += new EventHandler <DataReceivedEventArgs>(OnDataReceived);
        Client.ConnectionError += new EventHandler <Aws.GameLift.Realtime.Event.ErrorEventArgs>(OnConnectionErrorEvent);

        // Create a connection token to authenticate the client with the Realtime server
        // Player session IDs can be retrieved using AWS SDK for GameLift
        ConnectionToken connectionToken = new ConnectionToken(playerSessionId, connectionPayload);

        // Initiate a connection with the Realtime server with the given connection information
        Client.Connect(endpoint, remoteTcpPort, listeningUdpPort, connectionToken);
        activateListeners();
        Debug.Log("RTC instantiated");
    }
示例#2
0
    private void RealtimeClientConnect(string endpoint, int remoteTcpPort, int listeningUdpPort, ConnectionType connectionType,
                                       string playerSessionId, byte[] connectionPayload)
    {
        ClientLogger.LogHandler = (x) => GD.Print(x);

        // Create a client configuration to specify a secure or unsecure connection type
        // Best practice is to set up a secure connection using the connection type RT_OVER_WSS_DTLS_TLS12.
        ClientConfiguration clientConfiguration = new ClientConfiguration()
        {
            // C# notation to set the field ConnectionType in the new instance of ClientConfiguration
            ConnectionType = connectionType
        };

        realtimeClient = new Aws.GameLift.Realtime.Client(clientConfiguration);
        realtimeClient.DataReceived += OnDataReceived;
        ConnectionToken connectionToken = new ConnectionToken(playerSessionId, connectionPayload);

        realtimeClient.Connect(endpoint, remoteTcpPort, listeningUdpPort, connectionToken);
    }
示例#3
0
    private IEnumerator ConnectToServer(string ipAddr, int port, string tokenUID)
    {
        ClientLogger.LogHandler = (x) => Debug.Log(x);
        ConnectionToken token = new ConnectionToken(tokenUID, null);

        ClientConfiguration clientConfiguration;

        if (!usingTLS)
        {
            clientConfiguration = new ClientConfiguration
            {
                ConnectionType = ConnectionType.RT_OVER_WS_UDP_UNSECURED
            }
        }
        ;
        else
        {
            clientConfiguration = new ClientConfiguration
            {
                ConnectionType = ConnectionType.RT_OVER_WSS_DTLS_TLS12
            }
        };

        _client = new Aws.GameLift.Realtime.Client(clientConfiguration);

        _client.DataReceived += OnDataReceived;

        int ListenPort = 8921;

        clientManager.MessageReceived($"[client] TLS: {usingTLS} with Port: {ListenPort}");
        _client.Connect(ipAddr, port, ListenPort, token);

        while (true)
        {
            if (_client.ConnectedAndReady)
            {
                clientManager.MessageReceived("[client] Connected to server");
                break;
            }
            yield return(null);
        }
    }
示例#4
0
    // common code whether we are connecting to a GameLift hosted server or
    // a local server
    private IEnumerator ConnectToServer(string ipAddr, int port, string tokenUID)
    {
        ClientLogger.LogHandler = (x) => Debug.Log(x);
        ConnectionToken token = new ConnectionToken(tokenUID, null);

        ClientConfiguration clientConfiguration = ClientConfiguration.Default();

        _client = new Aws.GameLift.Realtime.Client(clientConfiguration);
        _client.ConnectionOpen  += new EventHandler(OnOpenEvent);
        _client.ConnectionClose += new EventHandler(OnCloseEvent);
        _client.DataReceived    += new EventHandler <DataReceivedEventArgs>(OnDataReceived);
        _client.ConnectionError += new EventHandler <Aws.GameLift.Realtime.Event.ErrorEventArgs>(OnConnectionErrorEvent);

        int UDPListenPort = FindAvailableUDPPort(DEFAULT_UDP_PORT, DEFAULT_UDP_PORT + 20);

        if (UDPListenPort == -1)
        {
            Debug.Log("Unable to find an open UDP listen port");
            yield break;
        }
        else
        {
            Debug.Log($"UDP listening on port: {UDPListenPort}");
        }

        Debug.Log($"[client] Attempting to connect to server ip: {ipAddr} TCP port: {port} Player Session ID: {tokenUID}");
        _client.Connect(string.IsNullOrEmpty(ipAddr) ? DEFAULT_ENDPOINT : ipAddr, port, UDPListenPort, token);

        while (true)
        {
            if (_client.ConnectedAndReady)
            {
                IsConnectedToServer = true;
                Debug.Log("[client] Connected to server");
                break;
            }
            yield return(null);
        }
    }