IEnumerator PingClock() { m_www = new WWW(m_url, m_timeCmdBytes, m_headers); double sendTime = HFTUtil.GetJSTimeInSeconds(); yield return(m_www); double receiveTime = HFTUtil.GetJSTimeInSeconds(); string err = m_www.error; string result = m_www.text; m_www = null; if (!String.IsNullOrEmpty(err)) { m_log.Tell("error: " + err + ", result:" + result); } else { HFTTimePing ping = JsonUtility.FromJson <HFTTimePing>(result); if (ping != null && ping.time > 0.0) { double duration = receiveTime - sendTime; double serverTime = ping.time + duration / 2; s_timeOffsetSeconds = serverTime - receiveTime; } } }
IEnumerator PingClock() { using (var www = new UnityWebRequest(m_url, UnityWebRequest.kHttpVerbPOST)) { www.uploadHandler = new UploadHandlerRaw(m_timeCmdBytes); www.uploadHandler.contentType = "application/json"; www.downloadHandler = new DownloadHandlerBuffer(); www.SetRequestHeader("Content-Type", "application/json"); double sendTime = HFTUtil.GetJSTimeInSeconds(); yield return(www.SendWebRequest()); double receiveTime = HFTUtil.GetJSTimeInSeconds(); string err = www.error; string result = www.downloadHandler.text; if (www.isHttpError || www.isNetworkError && !String.IsNullOrEmpty(err)) { m_log.Tell("error: " + err + ", result:" + result); } else { HFTTimePing ping = JsonUtility.FromJson <HFTTimePing>(result); if (ping != null && ping.time > 0.0) { double duration = receiveTime - sendTime; double serverTime = ping.time + duration / 2; s_timeOffsetSeconds = serverTime - receiveTime; } } } }