示例#1
0
        /// <summary>
        /// 주기적인 업데이트 호출
        /// 외부에서 주기적으로 (ex.30ms) 호출하여 내부로직을 처리해야 함
        /// </summary>
        /// <param name="elapsedTime">기존 업데이트로부터 지난 시간. 밀리세컨드(ms)</param>
        public void Update(int elapsedTime)
        {
            if (_isPossibleUpdate == false)
            {
                return;
            }

            try
            {
                if (_tcpChannel?.Update(elapsedTime) == false)
                {
                    throw new Exception("Disconnected due to TCP timeout");
                }

                if (_udpChannel?.Update(elapsedTime) == false)
                {
                    throw new Exception("Disconnected due to RUDP timeout");
                }
            }
            catch (Exception ex)
            {
                _isPossibleUpdate = false;
                OnError(ex);
                Close();
            }
        }
示例#2
0
        /// <summary>
        /// 주기적인 업데이트 호출
        /// 외부에서 주기적으로 (ex.30ms) 호출하여 내부로직을 처리해야 함
        /// </summary>
        /// <param name="elapsedTime">기존 업데이트로부터 지난 시간. 밀리세컨드(ms)</param>
        public void Update(int elapsedTime)
        {
            if (_isPossibleUpdate == false)
            {
                return;
            }

            try
            {
                if (_tcpChannel?.Update(elapsedTime) == false)
                {
                    throw new Exception("Disconnected due to TCP timeout");
                }

                if (_udpChannel?.Update(elapsedTime) == false)
                {
                    throw new Exception("Disconnected due to RUDP timeout");
                }

                _p2pGroup?.Update(elapsedTime);

                NetPacket packet;
                while (_receivedPacketQueue.TryDequeue(out packet) == true &&
                       packet != null)
                {
                    try
                    {
                        int headerSize = NetPacket.GetHeaderSize(packet.Property);
                        _packetReader.SetSource(packet.RawData, headerSize, packet.Size);

                        if (OnPreProcessPacket(packet, _packetReader) == true)
                        {
                            continue;
                        }

                        switch (packet.Property)
                        {
                        case PacketProperty.ResponseConnection:
                        {
                            SessionId  = packet.SessionIdForConnection;
                            _connectId = _packetReader.ReadInt64();

                            if (_clientOption.IsServiceUdp &&
                                _connectUdpLoopTask == null)
                            {
                                _connectUdpLoopTask = ConnectUdpLoopAsync(SessionId);
                            }
                        }
                        break;

                        default:
                        {
                            OnReceive(_packetReader).Wait();
                        }
                        break;
                        }
                    }
                    catch (Exception ex)
                    {
                        OnError(ex);
                        break;
                    }
                    finally
                    {
                        NetPool.PacketPool.Free(packet);
                    }
                }
            }
            catch (Exception ex)
            {
                _isPossibleUpdate = false;
                OnError(ex);
                Close();
            }
        }