Ejemplo n.º 1
0
        internal override void OnInitialization()
        {
            base.OnInitialization();

            _helper = Helper as INetworkHelper;
            _helper.LoadProtocolChannels(ChannelTypes);
            _helper.BeginConnectServerEvent += (cha) =>
            {
                BeginConnectServerEvent?.Invoke(cha);
            };
            _helper.ConnectServerSuccessEvent += (cha) =>
            {
                ConnectServerSuccessEvent?.Invoke(cha);
            };
            _helper.ConnectServerFailEvent += (cha) =>
            {
                ConnectServerFailEvent?.Invoke(cha);
            };
            _helper.DisconnectServerEvent += (cha) =>
            {
                DisconnectServerEvent?.Invoke(cha);
            };
            _helper.SendMessageEvent += (cha) =>
            {
                SendMessageEvent?.Invoke(cha);
            };
            _helper.ReceiveMessageEvent += (cha, mes) =>
            {
                ReceiveMessageEvent?.Invoke(cha, mes);
            };
        }
Ejemplo n.º 2
0
        private IEnumerator ConnectServerCoroutine(ProtocolChannelBase protocolChannel)
        {
            yield return(null);

            try
            {
                protocolChannel.DisconnectServer();
                protocolChannel.ConnectServer();
            }
            catch (Exception e)
            {
                Log.Error("连接服务器出错:" + e.ToString());
            }
            finally
            {
                if (protocolChannel.IsConnect)
                {
                    ConnectServerSuccessEvent?.Invoke(protocolChannel);
                }
                else
                {
                    ConnectServerFailEvent?.Invoke(protocolChannel);
                }
            }
        }