コード例 #1
0
        /// <summary>
        /// 关闭并清理网络频道辅助器。 ---自动调用
        /// </summary>
        void INetworkChannelHelper.Shutdown()
        {
            //m_NetworkChannel.NetworkChannelConnected -= OnNetworkConnected;
            //m_NetworkChannel.NetworkChannelClosed -= OnNetworkClosed;
            //m_NetworkChannel.NetworkChannelSended -= OnNetworkSendPacket;
            //m_NetworkChannel.NetworkChannelMissHeartBeat -= OnNetworkMissHeartBeat;
            //m_NetworkChannel.NetworkChannelError -= OnNetworkError;
            //m_NetworkChannel.NetworkChannelCustomError -= OnNetworkCustomError;

            GameEntry.Event.Unsubscribe(ZFramework.Runtime.NetworkConnectedEventArgs.EventId, OnNetworkConnected);
            GameEntry.Event.Unsubscribe(ZFramework.Runtime.NetworkClosedEventArgs.EventId, OnNetworkClosed);
            GameEntry.Event.Unsubscribe(ZFramework.Runtime.NetworkSendPacketEventArgs.EventId, OnNetworkSendPacket);
            GameEntry.Event.Unsubscribe(ZFramework.Runtime.NetworkMissHeartBeatEventArgs.EventId, OnNetworkMissHeartBeat);
            GameEntry.Event.Unsubscribe(ZFramework.Runtime.NetworkErrorEventArgs.EventId, OnNetworkError);
            GameEntry.Event.Unsubscribe(ZFramework.Runtime.NetworkCustomErrorEventArgs.EventId, OnNetworkCustomError);

            m_NetworkChannel     = null;
            m_CachedPacketHeader = null;
        }
コード例 #2
0
        /// <summary>
        /// 反序列消息包头。
        /// </summary>
        /// <param name="source">要反序列化的来源流。</param>
        /// <param name="customErrorData">用户自定义错误数据。</param>
        /// <returns></returns>
        IPacketHeader INetworkChannelHelper.DeserializePacketHeader(Stream source, out object customErrorData)
        {
            MemoryStream ms = source as MemoryStream;

            // 注意:此函数并不在主线程调用!
            Byte[] data = ms.ToArray();

            Byte[] length = new Byte[4];
            source.Read(length, 0, 4);
            Array.Reverse(length);  //反转数组转成小端

            Byte[] id = new Byte[4];
            source.Read(id, 0, 4);
            Array.Reverse(id);  //反转数组转成小端

            m_CachedPacketHeader = new SCPacketHeader(Utility.Converter.GetInt32(id));
            m_CachedPacketHeader.PacketLength = Utility.Converter.GetInt32(length);

            customErrorData = null;
            //m_CachedPacketHeader = Serializer.Deserialize<SCPacketHeader>(source);
            return(m_CachedPacketHeader);
        }