/// <summary> /// Initiates a reconnect to the SignalR server. /// </summary> public void Reconnect() { // Return if reconnect process already started. if (ReconnectStarted) { return; } ReconnectStarted = true; // Set ReconnectStartedAt only when the previous State is not Reconnecting, // so we keep the first date&time when we started reconnecting if (this.State != ConnectionStates.Reconnecting) { ReconnectStartedAt = DateTime.UtcNow; } this.State = ConnectionStates.Reconnecting; HTTPManager.Logger.Warning("SignalR Connection", "Reconnecting"); Transport.Reconnect(); if (PingRequest != null) { PingRequest.Abort(); } if (OnReconnecting != null) { try { OnReconnecting(this); } catch (Exception ex) { HTTPManager.Logger.Exception("SignalR Connection", "OnReconnecting", ex); } } }
// /// <summary> // /// 请求服务器文本 // /// </summary> // /// <param name="url"></param> // /// <param name="timeout"></param> // /// <param name="callback"></param> // /// <returns></returns> // public static IEnumerator RequestTextFromServer (string url, int timeout, Action<int,string> callback) // { // UnityWebRequest request = UnityWebRequest.Get(url); // request.timeout = timeout; // yield return request.SendWebRequest(); // // if (request.error != null||string.IsNullOrEmpty(request.downloadHandler.text)) // { // callback.InvokeGracefully(-1, request.error); // // } else { // // callback.InvokeGracefully(0, request.downloadHandler.text); // // } // request.Dispose(); // } public static IEnumerator GetTextFromServer(string from, float timeout, Action <int, string> callback) { HTTPRequest mHttpRequest = null; mHttpRequest = new HTTPRequest(new Uri(from), (req, resp) => { if (resp != null && req.Exception == null) { if (mHttpRequest != null) { mHttpRequest.Abort(); mHttpRequest.Dispose(); mHttpRequest = null; } callback(0, resp.DataAsText); } else { var errorInfo = req.Exception; if (mHttpRequest != null) { mHttpRequest.Abort(); mHttpRequest.Dispose(); mHttpRequest = null; } Debug.LogError(from + " >>>>>配置文件获取失败"); callback(-1, errorInfo != null?errorInfo.ToString():"ERROR"); } }) { ConnectTimeout = TimeSpan.FromSeconds(5), Timeout = TimeSpan.FromSeconds(10), DisableCache = true }; mHttpRequest.Send(); yield return(0); }
public void Abort(Manifest manifest) { HTTPRequest bestHTTPRequest = (HTTPRequest)manifest.EngineInstance; if (bestHTTPRequest != null) { bestHTTPRequest.Tag = null; if (bestHTTPRequest.State == HTTPRequestStates.Processing) { bestHTTPRequest.Abort(); } } manifest.EngineInstance = null; }
/// <summary> /// 停止尚未相应的请求 /// </summary> public void Cancel() { if (!_stopped && _request != null) { _stopped = true; try { _request.Abort(); } catch (Exception) { } _request = null; } }
void OnFragmentDownloaded(HTTPRequest req, HTTPResponse resp) { Manifest metadata = (Manifest)req.Tag; // HTTP requests need to have a Manifest attached to them to be valid // might have happened if it was an early abort, before a connection was set if (metadata == null) { req.Abort(); return; } if (resp != null) { metadata.ResponseCode = resp.StatusCode; } if (resp == null || resp.StatusCode >= 400 || req.Exception != null || req.Response == null) { metadata.SetError(ManifestErrors.UnknownDownloadError); if (OnEngineDownloadFailed != null) { OnEngineDownloadFailed(metadata); } metadata.EngineInstance = null; req.Tag = null; return; } metadata.Ping(); List <byte[]> downloadedFragments = resp.GetStreamedFragments(); if (downloadedFragments != null) { metadata.__Update(downloadedFragments); downloadedFragments.Clear(); } if (resp.IsStreamingFinished) { metadata.EngineInstance = null; req.Tag = null; if (OnEngineDownloadFinished != null) { OnEngineDownloadFinished(metadata); } } }
private bool OnData(HTTPRequest request, HTTPResponse response, byte[] dataFragment, int dataFragmentLength) { if (this.State == States.Connecting) { string contentType = response.GetFirstHeaderValue("content-type"); bool IsUpgraded = response.StatusCode == 200 && !string.IsNullOrEmpty(contentType) && contentType.ToLower().StartsWith("text/event-stream"); if (IsUpgraded) { ProtocolEventHelper.AddProtocol(this); if (this.OnOpen != null) { try { this.OnOpen(this); } catch (Exception ex) { HTTPManager.Logger.Exception("EventSource", "OnOpen", ex, request.Context); } } this.RetryCount = 0; this.State = States.Open; } else { this.State = States.Closing; request.Abort(); } } if (this.State == States.Closing) { return(true); } if (FeedData(dataFragment, dataFragmentLength)) { ProtocolEventHelper.EnqueueProtocolEvent(new ProtocolEventInfo(this)); } return(true); }
public void Clear(bool abort) { if (request != null) { request.OnUploadProgress = null; if (abort) { request.Abort(); } request.Clear(); request.Dispose(); } if (fileStream != null) { fileStream.Close(); fileStream.Dispose(); } }
void PhoneCheck() { if (phone.text == data.m_user.getPhone()) { return; } if (phone.text == "") { phone_illegal.gameObject.SetActive(false); phone_pass.gameObject.SetActive(false); phone_existed.gameObject.SetActive(false); return; } if (!data.phone.IsMatch(phone.text)) { phone_illegal.gameObject.SetActive(true); phone_existed.gameObject.SetActive(false); phone_pass.gameObject.SetActive(false); return; } phone_illegal.gameObject.SetActive(false); HTTPRequest request = new HTTPRequest(new Uri(data.IP + "/isPhoneExist?phone=" + phone.text), HTTPMethods.Get, (req, res) => { if (res.DataAsText == "true") { phone_existed.gameObject.SetActive(true); phone_pass.gameObject.SetActive(false); } else { phone_existed.gameObject.SetActive(false); phone_pass.gameObject.SetActive(true); } }); if (request_phone != null && request_phone.State == HTTPRequestStates.Processing) { request_phone.Abort(); } request_phone = request; request_phone.Send(); }
public void StopDownloadHttp() { if (null != m_request) { m_request.Abort(); } if (null != m_stream) { m_stream.Close(); } m_request = null; m_stream = null; m_localLength = 0; m_remoteLength = 0; m_zipIsOk = false; m_startDecompress = false; m_downloadComplated = false; }
// Token: 0x06005BD1 RID: 23505 RVA: 0x00200948 File Offset: 0x001FED48 private void OnDownloadProgress(HTTPRequest request, int downloaded, int length) { if (request == null) { return; } if (this.mLastDownloadedAmount == downloaded) { Debug.LogError("Server stopped responding. Could not download world."); UserMessage.SetMessage("Server stopped responding. Could not download world."); request.Abort(); } this.lastDownloadProgressTime = Time.unscaledTime; this.mLastDownloadedAmount = downloaded; this.Progress = (float)downloaded / (float)length; if (request != null && request.Response != null && request.Response.GetFirstHeaderValue("Content-Length") == null) { this.Progress = (float)downloaded; } }
void EmailCheck() { if (email.text == data.m_user.getEmail()) { return; } if (email.text == "") { email_pass.gameObject.SetActive(false); email_illegal.gameObject.SetActive(false); email_existed.gameObject.SetActive(false); return; } if (!data.email.IsMatch(email.text)) { email_illegal.gameObject.SetActive(true); email_existed.gameObject.SetActive(false); email_pass.gameObject.SetActive(false); return; } email_illegal.gameObject.SetActive(false); HTTPRequest request = new HTTPRequest(new Uri(data.IP + "/isEmailExist?email=" + email.text), HTTPMethods.Get, (req, res) => { if (res.DataAsText == "true") { email_existed.gameObject.SetActive(true); email_pass.gameObject.SetActive(false); } else { email_existed.gameObject.SetActive(false); email_pass.gameObject.SetActive(true); } }); if (request_email != null && request_email.State == HTTPRequestStates.Processing) { request_email.Abort(); } request_email = request; request_email.Send(); }
private static bool AbortRequestWhenTimedOut(DateTime now, object context) { HTTPRequest request = context as HTTPRequest; if (request.State >= HTTPRequestStates.Finished) { return(false); // don't repeat } // Protocols will shut down themselves if (request.Response is IProtocol) { return(false); } if (request.IsTimedOut) { HTTPManager.Logger.Information("RequestEventHelper", "AbortRequestWhenTimedOut - Request timed out. CurrentUri: " + request.CurrentUri.ToString(), request.Context); request.Abort(); return(false); // don't repeat } return(true); // repeat }
public override void stop() { base.stop(); request.Callback = null; request.Abort(); }
private void OnCompleteCallback(HTTPRequest originalRequest, HTTPResponse response) { switch (originalRequest.State) { // The request finished without any problem. case HTTPRequestStates.Finished: secureLog("Request Finished: Successfull:<" + response.IsSuccess + ">\n" + response.DataAsText); //No fue exitosa aunque termino if (!response.IsSuccess) { OnRequestFailed(); } else { formatData(response.DataAsText); if (!hasError()) { OnRequestComplete(); } else { if (hasCredentialError()) { if (OnBadCredentials != null) { OnBadCredentials(id); } } OnRequestFailed(); } } break; // The request finished with an unexpected error. // The request's Exception property may contain more information about the error. case HTTPRequestStates.Error: secureLogWarning("Request Finished with Error! " + (originalRequest.Exception != null ? (originalRequest.Exception.Message + "\n" + originalRequest.Exception.StackTrace) : "No Exception")); OnRequestFailed(); break; // The request aborted, initiated by the user. case HTTPRequestStates.Aborted: secureLogWarning("Request Aborted!"); break; // Ceonnecting to the server timed out. case HTTPRequestStates.ConnectionTimedOut: secureLogWarning("Connection Timed Out!"); OnRequestTimeout(); originalRequest.Abort(); break; // The request didn't finished in the given time. case HTTPRequestStates.TimedOut: secureLogWarning("Processing the request Timed Out!"); OnRequestTimeout(); originalRequest.Abort(); break; } }