Esempio n. 1
0
        void IModule.OnUpdate()
        {
            if (_client == null)
            {
                return;
            }

            // 更新网络客户端
            _client.Update();

            // 拉取网络包
            // 注意:如果服务器意外断开,未拉取的网络包将会丢失
            while (true)
            {
                INetworkPackage package = (INetworkPackage)_client.PickPackage();
                if (package == null)
                {
                    break;
                }

                NetworkPackageCallback?.Invoke(package);
            }

            // 侦测服务器主动断开连接
            if (States == ENetworkStates.Connected)
            {
                if (_client.IsConnected() == false)
                {
                    States = ENetworkStates.Disconnect;
                    NetworkEventDispatcher.SendDisconnectMsg();
                    CloseClient();
                    MotionLog.Warning("Server disconnect.");
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 断开连接
 /// </summary>
 public void DisconnectServer()
 {
     if (States == ENetworkStates.Connected)
     {
         States = ENetworkStates.Disconnect;
         NetworkEventDispatcher.SendDisconnectMsg();
         CloseClient();
     }
 }
Esempio n. 3
0
        void IModule.OnUpdate()
        {
            if (_client == null)
            {
                return;
            }

            // 更新网络客户端
            _client.Update();

            // 拉取网络包
            // 注意:如果服务器意外断开,未拉取的网络包将会丢失
            INetworkPackage package = (INetworkPackage)_client.PickPackage();

            if (package != null)
            {
                if (package.IsHotfixPackage)
                {
                    HotfixPackageCallback.Invoke(package);
                }
                else
                {
                    MonoPackageCallback.Invoke(package);
                }
            }

            // 侦测服务器主动断开连接
            if (States == ENetworkStates.Connected)
            {
                if (_client.IsConnected() == false)
                {
                    States = ENetworkStates.Disconnect;
                    NetworkEventDispatcher.SendDisconnectMsg();
                    CloseClient();
                    MotionLog.Log(ELogLevel.Warning, "Server disconnect.");
                }
            }
        }