/// <summary> /// 发送同步消息 /// </summary> /// <param name="msg"></param> private void SendSyncMessage(IMessage msg) { int messageId = msg.GetMessageId(); if (messageId == 0) { Debug.LogError(msg.GetType().ToString() + " no message Id"); } else { if (GlobalInfo.GAME_NETMODE == GameNetworkMode.Standalone) { MessageStandalonHandler.Call(msg); return; } if (this.m_httpClient == null) #if BEST_HTTP { this.m_httpClient = new BestHttpClient(EngineCoreEvents.BridgeEvent.GetServerAddress()); } #else { this.m_httpClient = new HttpClient(EngineCoreEvents.BridgeEvent.GetServerAddress()); } #endif SendMessageInternal(new RequestMessageWrapper(msg.GetMessageId(), msg, RequestMessageType.SYNC)); } }
/// <summary> /// 发送异步消息 /// </summary> /// <param name="msg"></param> private void SendAsyncMessage(IMessage msg) { if (GlobalInfo.GAME_NETMODE == GameNetworkMode.Standalone && msg.GetMessageId() != MessageDefine.CSRegGuestRequest) { MessageStandalonHandler.Call(msg); return; } if (string.IsNullOrEmpty(EngineCoreEvents.BridgeEvent.GetServerAddress())) { Debug.LogError("no server ip"); } else { if (this.m_httpClient == null) { #if BEST_HTTP this.m_httpClient = new BestHttpClient(EngineCoreEvents.BridgeEvent.GetServerAddress()); #else this.m_httpClient = new HttpClient(EngineCoreEvents.BridgeEvent.GetServerAddress()); #endif this.m_httpClient.OnErrorEvent = CommonTools.OnHttpError; } SendMessageInternal(new RequestMessageWrapper(msg.GetMessageId(), msg, RequestMessageType.ASYNC)); } }
private void RetryPendingMessages(bool retry) { if (!retry) { if (this.m_httpClient == null) { return; } this.m_httpClient.DestroyRetryMessage(); return; } if (this.m_httpClient == null) #if BEST_HTTP { this.m_httpClient = new BestHttpClient(EngineCoreEvents.BridgeEvent.GetServerAddress()); } #else { this.m_httpClient = new HttpClient(EngineCoreEvents.BridgeEvent.GetServerAddress()); } #endif this.m_httpClient.RestartRetryMessage(); }
private void SendMessageInternal(RequestMessageWrapper message) { if (this.m_networkStatus == NetworkStatus.TIMEOUT) { this.m_httpClient = null; } else if (this.m_networkStatus == NetworkStatus.WAITING_SYNC) { Debug.Log("waiting sync response"); return; } else { if (string.IsNullOrEmpty(EngineCoreEvents.BridgeEvent.GetServerAddress())) { Debug.LogError("no server ip"); } else { if (this.m_httpClient == null) #if BEST_HTTP { this.m_httpClient = new BestHttpClient(EngineCoreEvents.BridgeEvent.GetServerAddress()); } #else { this.m_httpClient = new HttpClient(EngineCoreEvents.BridgeEvent.GetServerAddress()); } #endif #if UNITY_DEBUG if (1901 != message.MessageId) { Debug.Log($"send message :{message.MessageBody.Descriptor.Name}"); } #endif this.m_httpClient.SendMessage(message); } } }