public void Send <TRequest, TResponse>(RequestDataBase data, Action <TResponse> callback) where TRequest : RequestBase <TRequest>, new() where TResponse : SimpleResponse, new()
        {
            Debug.Log("Send - " + typeof(TRequest));
            Debug.Log(data);
            var request = RequestBase <TRequest> .Create(_serverUrl, data);

            StartCoroutine(SendRequestWithTimer(request, () =>
            {
                request.OnSendCompleted();
                callback.Invoke(ParseResponse <TResponse, TRequest>(request));
            }, () =>
            {
                callback.Invoke(new TResponse {
                    error = "Timeout", errorCode = 408
                });
            }));
        }
Exemple #2
0
        /// <summary>
        /// Send a request to a server that has been extended from the RequestBase class
        /// </summary>
        /// <typeparam name="TRequest">Your request type that has been extended from the RequestBase class</typeparam>
        /// <typeparam name="TResponse">SimpleResponse type or RequestResponse type that has been extended from the SimpleResponse class</typeparam>
        /// <param name="requestData">Data container type that has been extended from the RequestDataBase class</param>
        /// <param name="resultCallback">Callback which signals the completion of communication with the server</param>
        public void Send <TRequest, TResponse>(RequestDataBase requestData, Action <TResponse> resultCallback) where TRequest : RequestBase <TRequest>, new() where TResponse : SimpleResponse, new()
        {
            Debug.Log("Send - " + typeof(TRequest));
            Debug.Log(requestData);
            var request = RequestBase <TRequest> .Create(_serverUrl, requestData);

            StartCoroutine(SendRequestWithTimer(request, compliteCallback: () =>
            {
                request.OnSendCompleted();
                if (resultCallback != null)
                {
                    resultCallback.Invoke(ParseResponse <TResponse, TRequest>(request));
                }
            }, timeoutCallback: () =>
            {
                if (resultCallback != null)
                {
                    resultCallback.Invoke(new TResponse {
                        error = "Timeout", errorCode = 408
                    });
                }
            }));
        }