async Task SendHTTPSPingRequest()

in GameLiftExampleUnityProject/Assets/Scripts/Client/Client.cs [66:103]


    async Task<double> SendHTTPSPingRequest(string requestUrl)
    {
        try
        {
            //First request to establish the connection
            var request = new HttpRequestMessage
            {
                Method = HttpMethod.Get,
                RequestUri = new Uri(requestUrl),
            };
            // Execute the request
            var client = new HttpClient();
            var resp = await client.SendAsync(request);

            // We measure the average of second and third requests to get the TCP latency without HTTPS handshake
            var startTime = DateTime.Now;
            request = new HttpRequestMessage
            {
                Method = HttpMethod.Get,
                RequestUri = new Uri(requestUrl),
            };
            resp = await client.SendAsync(request);
            request = new HttpRequestMessage
            {
                Method = HttpMethod.Get,
                RequestUri = new Uri(requestUrl),
            };
            resp = await client.SendAsync(request);
            // Total time
            var totalTime = (DateTime.Now - startTime).TotalMilliseconds / 2.0;
            return totalTime;
        }
        catch(Exception e)
        {
            print("Error reaching the endpoint " + requestUrl + ", setting latency to 1 second");
            return 1000.0;
        }
    }