示例#1
0
        void OnSendRequestFinished(HTTPRequest req, HTTPResponse resp)
        {
            sendRequestQueue.Remove(req);

            // error reason if there is any. We will call the manager's Error function if it's not empty.
            string reason = string.Empty;

            switch (req.State)
            {
            // The request finished without any problem.
            case HTTPRequestStates.Finished:
                if (resp.IsSuccess)
                {
                    HTTPManager.Logger.Information("Transport - " + this.Name, "Send - Request Finished Successfully! " + resp.DataAsText);

                    if (!string.IsNullOrEmpty(resp.DataAsText))
                    {
                        IServerMessage msg = TransportBase.Parse(Connection.JsonEncoder, resp.DataAsText);

                        if (msg != null)
                        {
                            Connection.OnMessage(msg);
                        }
                    }
                }
                else
                {
                    reason = string.Format("Send - Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
                                           resp.StatusCode,
                                           resp.Message,
                                           resp.DataAsText);
                }
                break;

            // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
            case HTTPRequestStates.Error:
                reason = "Send - Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception");
                break;

            // The request aborted, initiated by the user.
            case HTTPRequestStates.Aborted:
                reason = "Send - Request Aborted!";
                break;

            // Ceonnecting to the server is timed out.
            case HTTPRequestStates.ConnectionTimedOut:
                reason = "Send - Connection Timed Out!";
                break;

            // The request didn't finished in the given time.
            case HTTPRequestStates.TimedOut:
                reason = "Send - Processing the request Timed Out!";
                break;
            }

            if (!string.IsNullOrEmpty(reason))
            {
                Connection.Error(reason);
            }
        }
示例#2
0
 private void WSocket_OnMessage(BestHTTP.WebSocket.WebSocket webSocket, string message)
 {
     if (webSocket == this.wSocket)
     {
         IServerMessage msg = TransportBase.Parse(base.Connection.JsonEncoder, message);
         if (msg != null)
         {
             base.Connection.OnMessage(msg);
         }
     }
 }
示例#3
0
        private void OnPollRequestFinished(HTTPRequest req, HTTPResponse resp)
        {
            if (req.State == HTTPRequestStates.Aborted)
            {
                HTTPManager.Logger.Warning("Transport - " + base.Name, "Poll - Request Aborted!");
            }
            else
            {
                this.pollRequest = null;
                string str = string.Empty;
                switch (req.State)
                {
                case HTTPRequestStates.Finished:
                {
                    if (!resp.IsSuccess)
                    {
                        str = $"Poll - Request Finished Successfully, but the server sent an error. Status Code: {resp.StatusCode}-{resp.Message} Message: {resp.DataAsText}";
                        break;
                    }
                    HTTPManager.Logger.Information("Transport - " + base.Name, "Poll - Request Finished Successfully! " + resp.DataAsText);
                    IServerMessage msg = TransportBase.Parse(base.Connection.JsonEncoder, resp.DataAsText);
                    if (msg != null)
                    {
                        base.Connection.OnMessage(msg);
                        MultiMessage message2 = msg as MultiMessage;
                        if ((message2 != null) && message2.PollDelay.HasValue)
                        {
                            this.PollDelay = message2.PollDelay.Value;
                        }
                        this.LastPoll = DateTime.UtcNow;
                    }
                    break;
                }

                case HTTPRequestStates.Error:
                    str = "Poll - Request Finished with Error! " + ((req.Exception == null) ? "No Exception" : (req.Exception.Message + "\n" + req.Exception.StackTrace));
                    break;

                case HTTPRequestStates.ConnectionTimedOut:
                    str = "Poll - Connection Timed Out!";
                    break;

                case HTTPRequestStates.TimedOut:
                    str = "Poll - Processing the request Timed Out!";
                    break;
                }
                if (!string.IsNullOrEmpty(str))
                {
                    base.Connection.Error(str);
                }
            }
        }
示例#4
0
        void WSocket_OnMessage(WebSocket.WebSocket webSocket, string message)
        {
            if (webSocket != wSocket)
            {
                return;
            }

            IServerMessage msg = TransportBase.Parse(Connection.JsonEncoder, message);

            if (msg != null)
            {
                Connection.OnMessage(msg);
            }
        }
示例#5
0
        private void OnEventSourceMessage(EventSource eventSource, BestHTTP.ServerSentEvents.Message message)
        {
            if (message.Data.Equals("initialized"))
            {
                base.OnConnected();

                return;
            }

            IServerMessage msg = TransportBase.Parse(Connection.JsonEncoder, message.Data);

            if (msg != null)
            {
                Connection.OnMessage(msg);
            }
        }
        private void OnSendRequestFinished(HTTPRequest req, HTTPResponse resp)
        {
            this.sendRequestQueue.Remove(req);
            string str = string.Empty;

            switch (req.State)
            {
            case HTTPRequestStates.Finished:
                if (!resp.IsSuccess)
                {
                    str = $"Send - Request Finished Successfully, but the server sent an error. Status Code: {resp.StatusCode}-{resp.Message} Message: {resp.DataAsText}";
                    break;
                }
                HTTPManager.Logger.Information("Transport - " + base.Name, "Send - Request Finished Successfully! " + resp.DataAsText);
                if (!string.IsNullOrEmpty(resp.DataAsText))
                {
                    IServerMessage msg = TransportBase.Parse(base.Connection.JsonEncoder, resp.DataAsText);
                    if (msg != null)
                    {
                        base.Connection.OnMessage(msg);
                    }
                }
                break;

            case HTTPRequestStates.Error:
                str = "Send - Request Finished with Error! " + ((req.Exception == null) ? "No Exception" : (req.Exception.Message + "\n" + req.Exception.StackTrace));
                break;

            case HTTPRequestStates.Aborted:
                str = "Send - Request Aborted!";
                break;

            case HTTPRequestStates.ConnectionTimedOut:
                str = "Send - Connection Timed Out!";
                break;

            case HTTPRequestStates.TimedOut:
                str = "Send - Processing the request Timed Out!";
                break;
            }
            if (!string.IsNullOrEmpty(str))
            {
                base.Connection.Error(str);
            }
        }
        void WSocket_OnMessage(WebSocket.WebSocket webSocket, string message)
        {
            if (webSocket != wSocket)
            {
                return;
            }

#if UNITY_EDITOR
            VKDebug.Log(message, VKCommon.HEX_GREEN);
#endif

            IServerMessage msg = TransportBase.Parse(Connection.JsonEncoder, message);

            if (msg != null)
            {
                Connection.OnMessage(msg);
            }
        }
示例#8
0
        void OnPollRequestFinished(HTTPRequest req, HTTPResponse resp)
        {
            // When Stop() called on the transport.
            // In Stop() we set the pollRequest to null, but a new poll request can be made after a quick reconnection, and there is a chanse that
            // in this handler function we can null out the new request. So we return early here.
            if (req.State == HTTPRequestStates.Aborted)
            {
                HTTPManager.Logger.Warning("Transport - " + this.Name, "Poll - Request Aborted!");
                return;
            }

            // Set the pollRequest to null, now we can send out a new one
            pollRequest = null;

            // error reason if there is any. We will call the manager's Error function if it's not empty.
            string reason = string.Empty;

            switch (req.State)
            {
            // The request finished without any problem.
            case HTTPRequestStates.Finished:
                if (resp.IsSuccess)
                {
                    HTTPManager.Logger.Information("Transport - " + this.Name, "Poll - Request Finished Successfully! " + resp.DataAsText);

                    IServerMessage msg = TransportBase.Parse(Connection.JsonEncoder, resp.DataAsText);

                    if (msg != null)
                    {
                        Connection.OnMessage(msg);

                        MultiMessage multiple = msg as MultiMessage;
                        if (multiple != null && multiple.PollDelay.HasValue)
                        {
                            PollDelay = multiple.PollDelay.Value;
                        }

                        LastPoll = DateTime.UtcNow;
                    }
                }
                else
                {
                    reason = string.Format("Poll - Request Finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
                                           resp.StatusCode,
                                           resp.Message,
                                           resp.DataAsText);
                }
                break;

            // The request finished with an unexpected error. The request's Exception property may contain more info about the error.
            case HTTPRequestStates.Error:
                reason = "Poll - Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception");
                break;

            // Ceonnecting to the server is timed out.
            case HTTPRequestStates.ConnectionTimedOut:
                reason = "Poll - Connection Timed Out!";
                break;

            // The request didn't finished in the given time.
            case HTTPRequestStates.TimedOut:
                reason = "Poll - Processing the request Timed Out!";
                break;
            }

            if (!string.IsNullOrEmpty(reason))
            {
                Connection.Error(reason);
            }
        }