Example #1
0
        private void OnAbortRequestFinished(HTTPRequest req, HTTPResponse resp)
        {
            HTTPRequestStates state = req.State;

            if (state == HTTPRequestStates.Finished)
            {
                if (resp.IsSuccess)
                {
                    HTTPManager.Logger.Information("Transport - " + Name, "Abort - Returned: " + resp.DataAsText);
                    if (State == TransportStates.Closing)
                    {
                        AbortFinished();
                    }
                    return;
                }
                HTTPManager.Logger.Warning("Transport - " + Name, $"Abort - Handshake request finished Successfully, but the server sent an error. Status Code: {resp.StatusCode}-{resp.Message} Message: {resp.DataAsText} Uri: {req.CurrentUri}");
            }
            HTTPManager.Logger.Information("Transport - " + Name, "Abort request state: " + req.State.ToString());
            int num = (int)req.Tag;

            if (num++ < 5)
            {
                req.Tag = num;
                req.Send();
            }
            else
            {
                Connection.Error("Failed to send Abort request!");
            }
        }
Example #2
0
 internal Result onError(string error, HTTPRequestStates s, HTTPResponse resp, RestException e)
 {
     errorMsg  = error;
     states    = s;
     response  = resp;
     exception = e;
     succeed   = false;
     return(this);
 }
        public RequestEventInfo(HTTPRequest request, byte[] data, int dataLength)
        {
            this.SourceRequest = request;
            this.Event         = RequestEvents.StreamingData;
            this.State         = HTTPRequestStates.Initial;

            this.Progress   = this.ProgressLength = 0;
            this.Data       = data;
            this.DataLength = dataLength;
        }
        public RequestEventInfo(HTTPRequest request, HTTPRequestStates newState)
        {
            this.SourceRequest = request;
            this.Event         = RequestEvents.StateChange;
            this.State         = newState;

            this.Progress   = this.ProgressLength = 0;
            this.Data       = null;
            this.DataLength = 0;
        }
        public RequestEventInfo(HTTPRequest request, RequestEvents @event, long progress, long progressLength)
        {
            this.SourceRequest = request;
            this.Event         = @event;
            this.State         = HTTPRequestStates.Initial;

            this.Progress       = progress;
            this.ProgressLength = progressLength;
            this.Data           = null;
            this.DataLength     = 0;
        }
Example #6
0
        private void CloseWithError(HTTPRequestStates state, string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                this.baseRequest.Exception = new Exception(message);
            }
            this.baseRequest.State = state;

            this.closed = true;

            HTTPManager.Heartbeats.Unsubscribe(this);
            HTTPUpdateDelegator.OnApplicationForegroundStateChanged -= OnApplicationForegroundStateChanged;

            CloseStream();
            ProtocolEventHelper.EnqueueProtocolEvent(new ProtocolEventInfo(this));
        }
Example #7
0
        public IEnumerator Send()
        {
            if (request.uploadHandler == null)
            {
                request.uploadHandler = new UploadHandlerRaw(null);
            }

            // 通信開始
            yield return(request.SendWebRequest());

            this.State     = request.isDone ? HTTPRequestStates.Finished : HTTPRequestStates.Error;
            this.Exception = new Exception(request.error);
            act(this, new HTTPResponse {
                IsSuccess = string.IsNullOrEmpty(request.error), Data = request.downloadHandler.data, StatusCode = (int)request.responseCode
            });
        }
Example #8
0
        private void OnHandshakeCallback(HTTPRequest req, HTTPResponse resp)
        {
            this.HandshakeRequest = null;
            HTTPRequestStates state = req.State;

            if (state != HTTPRequestStates.Finished)
            {
                if (state != HTTPRequestStates.Error)
                {
                    this.RaiseOnError(req.State.ToString());
                }
                else
                {
                    this.RaiseOnError((req.Exception == null) ? string.Empty : (req.Exception.Message + " " + req.Exception.StackTrace));
                }
            }
            else if (resp.IsSuccess)
            {
                HTTPManager.Logger.Information("HandshakeData", "Handshake data arrived: " + resp.DataAsText);
                int num = resp.DataAsText.IndexOf("{");
                if (num < 0)
                {
                    this.RaiseOnError("Invalid handshake text: " + resp.DataAsText);
                    return;
                }
                if (this.Parse(resp.DataAsText.Substring(num)) == null)
                {
                    this.RaiseOnError("Parsing Handshake data failed: " + resp.DataAsText);
                    return;
                }
                if (this.OnReceived != null)
                {
                    this.OnReceived(this);
                    this.OnReceived = null;
                }
            }
            else
            {
                this.RaiseOnError(string.Format("Handshake request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2} Uri: {3}", new object[]
                {
                    resp.StatusCode,
                    resp.Message,
                    resp.DataAsText,
                    req.CurrentUri
                }));
            }
        }
Example #9
0
        private void OnStartRequestFinished(HTTPRequest req, HTTPResponse resp)
        {
            HTTPRequestStates state = req.State;

            if (state == HTTPRequestStates.Finished)
            {
                if (resp.IsSuccess)
                {
                    HTTPManager.Logger.Information("Transport - " + Name, "Start - Returned: " + resp.DataAsText);
                    string text = Connection.ParseResponse(resp.DataAsText);
                    if (text != "started")
                    {
                        Connection.Error($"Expected 'started' response, but '{text}' found!");
                    }
                    else
                    {
                        State = TransportStates.Started;
                        Started();
                        Connection.TransportStarted();
                    }
                    return;
                }
                HTTPManager.Logger.Warning("Transport - " + Name, $"Start - request finished Successfully, but the server sent an error. Status Code: {resp.StatusCode}-{resp.Message} Message: {resp.DataAsText} Uri: {req.CurrentUri}");
            }
            HTTPManager.Logger.Information("Transport - " + Name, "Start request state: " + req.State.ToString());
            int num = (int)req.Tag;

            if (num++ < 5)
            {
                req.Tag = num;
                req.Send();
            }
            else
            {
                Connection.Error("Failed to send Start request.");
            }
        }