請求, 不等待回應

private void SendRequest()
{
    var req = new ReqEcho();
    req.Send(); // 或 CasinoNetManager.Send(req);
}

請求, 等待回應

private IEnumerator SendRequest()
{
    var req = new ReqEcho();
    yield return req.SendAsync(); // 或 yield return CasinoNetManager.SendAsync(req);

    var result = req.Result;
    if (result.IsValid) // IsValid裡判斷了Method是否不為空且Status==0
    {
        // 處理回應的Json資料
        DebugEx.Log(string.Format("Method:{0},Data:{1}", result.Method, result.Data));
    }
    else
    {
        // 錯誤處理
        DebugEx.LogWarning(string.Format("Status:{0}", result.Status));
    }
}

監聽Server主動的回應

void Start()
{
    CasinoNetManager.OnDataReceived += OnDataReceived;
}

private void OnDataReceived(CasinoResponse result)
{
    if (result.IsValid) // IsValid裡判斷了Method是否不為空且Status==0
    {
        // 處理回應的Json資料
        DebugEx.Log(string.Format("Method:{0},Data:{1}", result.Method, result.Data));
    }
    else
    {
        // 錯誤處理
        DebugEx.LogWarning(string.Format("Status:{0}", result.Status));
    }
}

results matching ""

    No results matching ""