当前位置: 首页>>代码示例>>C#>>正文


C# NetOutgoingMessage.GetEncodedSize方法代码示例

本文整理汇总了C#中Lidgren.Network.NetOutgoingMessage.GetEncodedSize方法的典型用法代码示例。如果您正苦于以下问题:C# NetOutgoingMessage.GetEncodedSize方法的具体用法?C# NetOutgoingMessage.GetEncodedSize怎么用?C# NetOutgoingMessage.GetEncodedSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lidgren.Network.NetOutgoingMessage的用法示例。


在下文中一共展示了NetOutgoingMessage.GetEncodedSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EnqueueMessage

		// called by SendMessage() and NetPeer.SendMessage; ie. may be user thread
		internal NetSendResult EnqueueMessage(NetOutgoingMessage msg, NetDeliveryMethod method, int sequenceChannel)
		{
			if (m_status != NetConnectionStatus.Connected)
				return NetSendResult.FailedNotConnected;

			NetMessageType tp = (NetMessageType)((int)method + sequenceChannel);
			msg.m_messageType = tp;

			// TODO: do we need to make this more thread safe?
			int channelSlot = (int)method - 1 + sequenceChannel;
			NetSenderChannelBase chan = m_sendChannels[channelSlot];
			if (chan == null)
				chan = CreateSenderChannel(tp);

			if (msg.GetEncodedSize() > m_currentMTU)
				throw new NetException("Message too large! Fragmentation failure?");

			var retval = chan.Enqueue(msg);
			if (retval == NetSendResult.Sent && m_peerConfiguration.m_autoFlushSendQueue == false)
				retval = NetSendResult.Queued; // queued since we're not autoflushing
			return retval;
		}
开发者ID:DrPandemic,项目名称:EraParadox,代码行数:23,代码来源:NetConnection.cs

示例2: QueueSendMessage

		// Queue an item for immediate sending on the wire
		// This method is called from the ISenderChannels
		internal void QueueSendMessage(NetOutgoingMessage om, int seqNr)
		{
			m_peer.VerifyNetworkThread();

			int sz = om.GetEncodedSize();
			if (sz > m_currentMTU)
				m_peer.LogWarning("Message larger than MTU! Fragmentation must have failed!");

			if (m_sendBufferWritePtr + sz > m_currentMTU)
			{
				bool connReset; // TODO: handle connection reset
				NetException.Assert(m_sendBufferWritePtr > 0 && m_sendBufferNumMessages > 0); // or else the message should have been fragmented earlier
				m_peer.SendPacket(m_sendBufferWritePtr, m_remoteEndPoint, m_sendBufferNumMessages, out connReset);
				m_statistics.PacketSent(m_sendBufferWritePtr, m_sendBufferNumMessages);
				m_sendBufferWritePtr = 0;
				m_sendBufferNumMessages = 0;
			}

			m_sendBufferWritePtr = om.Encode(m_peer.m_sendBuffer, m_sendBufferWritePtr, seqNr);
			m_sendBufferNumMessages++;

			NetException.Assert(m_sendBufferWritePtr > 0, "Encoded zero size message?");
			NetException.Assert(m_sendBufferNumMessages > 0);
		}
开发者ID:DrPandemic,项目名称:EraParadox,代码行数:26,代码来源:NetConnection.cs

示例3: QueueSendMessage

        // Queue an item for immediate sending on the wire
        // This method is called from the ISenderChannels
        internal void QueueSendMessage(NetOutgoingMessage om, int seqNr)
        {
            m_peer.VerifyNetworkThread();

            int sz = om.GetEncodedSize();
            //if (sz > m_currentMTU)
            //	m_peer.LogWarning("Message larger than MTU! Fragmentation must have failed!");

            bool connReset; // TODO: handle connection reset

            // can fit this message together with previously written to buffer?
            if (m_sendBufferWritePtr + sz > m_currentMTU)
            {
                if (m_sendBufferWritePtr > 0 && m_sendBufferNumMessages > 0)
                {
                    // previous message in buffer; send these first
                    m_peer.SendPacket(m_sendBufferWritePtr, m_remoteEndPoint, m_sendBufferNumMessages, out connReset);
                    m_statistics.PacketSent(m_sendBufferWritePtr, m_sendBufferNumMessages);
                    m_sendBufferWritePtr = 0;
                    m_sendBufferNumMessages = 0;
                }
            }

            // encode it into buffer regardless if it (now) fits within MTU or not
            m_sendBufferWritePtr = om.Encode(m_peer.m_sendBuffer, m_sendBufferWritePtr, seqNr);
            m_sendBufferNumMessages++;

            if (m_sendBufferWritePtr > m_currentMTU)
            {
                // send immediately; we're already over MTU
                m_peer.SendPacket(m_sendBufferWritePtr, m_remoteEndPoint, m_sendBufferNumMessages, out connReset);
                m_statistics.PacketSent(m_sendBufferWritePtr, m_sendBufferNumMessages);
                m_sendBufferWritePtr = 0;
                m_sendBufferNumMessages = 0;
            }
        }
开发者ID:AugustoAngeletti,项目名称:Lindgren-Unity-Port,代码行数:38,代码来源:NetConnection.cs

示例4: SendMessage

		/// <summary>
		/// Send a message to a list of connections
		/// </summary>
		/// <param name="msg">The message to send</param>
		/// <param name="recipients">The list of recipients to send to</param>
		/// <param name="method">How to deliver the message</param>
		/// <param name="sequenceChannel">Sequence channel within the delivery method</param>
		public void SendMessage(NetOutgoingMessage msg, List<NetConnection> recipients, NetDeliveryMethod method, int sequenceChannel)
		{
			if (msg == null)
				throw new ArgumentNullException("msg");
			if (recipients == null)
				throw new ArgumentNullException("recipients");
			if (recipients.Count < 1)
				throw new NetException("recipients must contain at least one item");
			if (method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.ReliableUnordered)
				NetException.Assert(sequenceChannel == 0, "Delivery method " + method + " cannot use sequence channels other than 0!");
			if (msg.m_isSent)
				throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently");

			int mtu = GetMTU(recipients);

			msg.m_isSent = true;

			int len = msg.GetEncodedSize();
			if (len <= mtu)
			{
				Interlocked.Add(ref msg.m_recyclingCount, recipients.Count);
				foreach (NetConnection conn in recipients)
				{
					if (conn == null)
					{
						Interlocked.Decrement(ref msg.m_recyclingCount);
						continue;
					}
					NetSendResult res = conn.EnqueueMessage(msg, method, sequenceChannel);
					if (res != NetSendResult.Queued && res != NetSendResult.Sent)
						Interlocked.Decrement(ref msg.m_recyclingCount);
				}
			}
			else
			{
				// message must be fragmented!
				SendFragmentedMessage(msg, recipients, method, sequenceChannel);
			}

			return;
		}
开发者ID:imGoose,项目名称:SkyrimOnline,代码行数:48,代码来源:NetPeer.Send.cs

示例5: EnqueueMessage

		// called by SendMessage() and NetPeer.SendMessage; ie. may be user thread
		internal NetSendResult EnqueueMessage(NetOutgoingMessage msg, NetDeliveryMethod method, int sequenceChannel)
		{
			NetMessageType tp = (NetMessageType)((int)method + sequenceChannel);
			msg.m_messageType = tp;

			// TODO: do we need to make this more thread safe?
			int channelSlot = (int)method - 1 + sequenceChannel;
			NetSenderChannelBase chan = m_sendChannels[channelSlot];
			if (chan == null)
				chan = CreateSenderChannel(tp);

			if (msg.GetEncodedSize() > m_currentMTU)
				throw new NetException("Message too large! Fragmentation failure?");

			return chan.Enqueue(msg);
		}
开发者ID:Dahie,项目名称:September-1983,代码行数:17,代码来源:NetConnection.cs


注:本文中的Lidgren.Network.NetOutgoingMessage.GetEncodedSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。