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


C# NetDeliveryMethod类代码示例

本文整理汇总了C#中NetDeliveryMethod的典型用法代码示例。如果您正苦于以下问题:C# NetDeliveryMethod类的具体用法?C# NetDeliveryMethod怎么用?C# NetDeliveryMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: SendMessage

        public void SendMessage(NetOutgoingMessage msg, IList<NetConnection> recipients, NetDeliveryMethod method, int sequenceChannel)
        {
            if (msg == null)
                throw new ArgumentNullException("msg");
            if (recipients == null)
                throw new ArgumentNullException("recipients");
            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 len = msg.LengthBytes;
            if (len <= m_configuration.MaximumTransmissionUnit)
            {
                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.Dropped)
                        Interlocked.Decrement(ref msg.m_recyclingCount);
                }
            }
            else
            {
                // message must be fragmented!
                SendFragmentedMessage(msg, recipients, method, sequenceChannel);
            }

            return;
        }
开发者ID:andva,项目名称:Eulerian-ShootEmUp,代码行数:35,代码来源:NetPeer.Send.cs

示例2: MessageTypeDescription

 public MessageTypeDescription(ushort messageTypeId, Type messageType, int sequenceChannel, NetDeliveryMethod deliveryMethod)
 {
     _messageTypeId = messageTypeId;
     _messageType = messageType;
     _sequenceChannel = sequenceChannel;
     _deliveryMethod = deliveryMethod;
 }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:7,代码来源:IMessageTypeManager.cs

示例3: SendFragmentedMessage

		// on user thread
		private NetSendResult SendFragmentedMessage(NetOutgoingMessage msg, IList<NetConnection> recipients, NetDeliveryMethod method, int sequenceChannel)
		{
			// Note: this group id is PER SENDING/NetPeer; ie. same id is sent to all recipients;
			// this should be ok however; as long as recipients differentiate between same id but different sender
			int group = Interlocked.Increment(ref m_lastUsedFragmentGroup);
			if (group >= NetConstants.MaxFragmentationGroups)
			{
				// @TODO: not thread safe; but in practice probably not an issue
				m_lastUsedFragmentGroup = 1;
				group = 1;
			}
			msg.m_fragmentGroup = group;

			// do not send msg; but set fragmentgroup in case user tries to recycle it immediately

			// create fragmentation specifics
			int totalBytes = msg.LengthBytes;

			// determine minimum mtu for all recipients
			int mtu = GetMTU(recipients);
			int bytesPerChunk = NetFragmentationHelper.GetBestChunkSize(group, totalBytes, mtu);

			int numChunks = totalBytes / bytesPerChunk;
			if (numChunks * bytesPerChunk < totalBytes)
				numChunks++;

			NetSendResult retval = NetSendResult.Sent;

			int bitsPerChunk = bytesPerChunk * 8;
			int bitsLeft = msg.LengthBits;
			for (int i = 0; i < numChunks; i++)
			{
				NetOutgoingMessage chunk = CreateMessage(0);

				chunk.m_bitLength = (bitsLeft > bitsPerChunk ? bitsPerChunk : bitsLeft);
				chunk.m_data = msg.m_data;
				chunk.m_fragmentGroup = group;
				chunk.m_fragmentGroupTotalBits = totalBytes * 8;
				chunk.m_fragmentChunkByteSize = bytesPerChunk;
				chunk.m_fragmentChunkNumber = i;

				NetException.Assert(chunk.m_bitLength != 0);
				NetException.Assert(chunk.GetEncodedSize() < mtu);

				Interlocked.Add(ref chunk.m_recyclingCount, recipients.Count);

				foreach (NetConnection recipient in recipients)
				{
					var res = recipient.EnqueueMessage(chunk, method, sequenceChannel);
					if (res == NetSendResult.Dropped)
						Interlocked.Decrement(ref chunk.m_recyclingCount);
					if ((int)res > (int)retval)
						retval = res; // return "worst" result
				}

				bitsLeft -= bitsPerChunk;
			}

			return retval;
		}
开发者ID:Aslan125,项目名称:GameNet,代码行数:61,代码来源:NetPeer.Fragmentation.cs

示例4: SendMessage

        /// <summary>
        /// Send a message to a specific connection
        /// </summary>
        /// <param name="msg">The message to send</param>
        /// <param name="recipient">The recipient connection</param>
        /// <param name="method">How to deliver the message</param>
        /// <param name="sequenceChannel">Sequence channel within the delivery method</param>
        public NetSendResult SendMessage(NetOutgoingMessage msg, NetConnection recipient, NetDeliveryMethod method, int sequenceChannel)
        {
            if (msg == null)
                throw new ArgumentNullException("msg");
            if (recipient == null)
                throw new ArgumentNullException("recipient");
            if (sequenceChannel >= NetConstants.NetChannelsPerDeliveryMethod)
                throw new ArgumentOutOfRangeException("sequenceChannel");

            NetException.Assert(
                ((method != NetDeliveryMethod.Unreliable && method != NetDeliveryMethod.ReliableUnordered) ||
                ((method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.ReliableUnordered) && sequenceChannel == 0)),
                "Delivery method " + method + " cannot use sequence channels other than 0!"
            );

            NetException.Assert(method != NetDeliveryMethod.Unknown, "Bad delivery method!");

            if (msg.m_isSent)
                throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently");
            msg.m_isSent = true;

            int len = NetConstants.UnfragmentedMessageHeaderSize + msg.LengthBytes; // headers + length, faster than calling msg.GetEncodedSize
            if (len <= recipient.m_currentMTU)
            {
                Interlocked.Increment(ref msg.m_recyclingCount);
                return recipient.EnqueueMessage(msg, method, sequenceChannel);
            }
            else
            {
                // message must be fragmented!
                SendFragmentedMessage(msg, new NetConnection[] { recipient }, method, sequenceChannel);
                return NetSendResult.Queued; // could be different for each connection; Queued is "most true"
            }
        }
开发者ID:ncoder,项目名称:MonoGame,代码行数:41,代码来源:NetPeer.Send.cs

示例5: SendToAll

		/// <summary>
		/// Send a message to all connections
		/// </summary>
		/// <param name="msg">The message to send</param>
		/// <param name="method">How to deliver the message</param>
		public void SendToAll(NetOutgoingMessage msg, NetDeliveryMethod method)
		{
			var all = this.Connections;
			if (all.Count <= 0)
				return;

			SendMessage(msg, all, method, 0);
		}
开发者ID:Werkheisera2,项目名称:RaginRovers,代码行数:13,代码来源:NetServer.cs

示例6: Reply

 public void Reply(NetDeliveryMethod method)
 {
     if (CanReply) {
         this.Send(LastReceivedSender, method);
     } else {
         throw new Exception("Can only reply in 'Execute' method of a Message."); //It's the only way we know who to reply to.
     }
 }
开发者ID:CloneDeath,项目名称:Xanatos,代码行数:8,代码来源:Message.cs

示例7: Connect

        // called by the UI
        internal static void Connect(string host, int port, string deliveryMethod, int sequenceChannel)
        {
            s_client.Start();

            s_method = (NetDeliveryMethod)Enum.Parse(typeof(NetDeliveryMethod), deliveryMethod);
            s_sequenceChannel = sequenceChannel;

            s_client.Connect(host, port);
        }
开发者ID:wallymathieu,项目名称:WindowsGame9,代码行数:10,代码来源:Program.cs

示例8: SendToAll

		/// <summary>
		/// Send a message to all connections
		/// </summary>
		/// <param name="msg">The message to send</param>
		/// <param name="method">How to deliver the message</param>
		public void SendToAll(NetOutgoingMessage msg, NetDeliveryMethod method)
		{
			var all = this.Connections;
			if (all.Count <= 0) {
				if (msg.m_isSent == false)
					Recycle(msg);
				return;
			}

			SendMessage(msg, all, method, 0);
		}
开发者ID:g1111111g,项目名称:lidgren-network-gen3,代码行数:16,代码来源:NetServer.cs

示例9: NetUnreliableSenderChannel

		internal NetUnreliableSenderChannel(NetConnection connection, int windowSize, NetDeliveryMethod method)
		{
			m_connection = connection;
			m_windowSize = windowSize;
			m_windowStart = 0;
			m_sendStart = 0;
			m_receivedAcks = new NetBitVector(NetConstants.NumSequenceNumbers);
			m_queuedSends = new NetQueue<NetOutgoingMessage>(8);

			m_doFlowControl = true;
			if (method == NetDeliveryMethod.Unreliable && connection.Peer.Configuration.SuppressUnreliableUnorderedAcks == true)
				m_doFlowControl = false;
		}
开发者ID:g1111111g,项目名称:lidgren-network-gen3,代码行数:13,代码来源:NetUnreliableSenderChannel.cs

示例10: SendMessage

 public bool SendMessage(NetOutgoingMessage message, NetDeliveryMethod method, ChannelTypes channelType)
 {
     if (_netClient.ConnectionStatus == NetConnectionStatus.Connected)
     {
         _netClient.SendMessage(message, method, (int)channelType);
         return true;
     }
     else
     {
         _packetCache.Add(new Tuple<NetOutgoingMessage, NetDeliveryMethod, ChannelTypes>(message, method, channelType));
         return false;
     }
 }
开发者ID:JohnLamontagne,项目名称:CEngineSharp,代码行数:13,代码来源:NetManager.cs

示例11: SendFragmentedMessage

		// on user thread
		private void SendFragmentedMessage(NetOutgoingMessage msg, IList<NetConnection> recipients, NetDeliveryMethod method, int sequenceChannel)
		{
			int group = Interlocked.Increment(ref m_lastUsedFragmentGroup);
			if (group >= NetConstants.MaxFragmentationGroups)
			{
				// TODO: not thread safe; but in practice probably not an issue
				m_lastUsedFragmentGroup = 1;
				group = 1;
			}
			msg.m_fragmentGroup = group;

			// do not send msg; but set fragmentgroup in case user tries to recycle it immediately

			// create fragmentation specifics
			int totalBytes = msg.LengthBytes;

			// determine minimum mtu for all recipients
			int mtu = GetMTU(recipients);
			int bytesPerChunk = NetFragmentationHelper.GetBestChunkSize(group, totalBytes, mtu);

			int numChunks = totalBytes / bytesPerChunk;
			if (numChunks * bytesPerChunk < totalBytes)
				numChunks++;

			int bitsPerChunk = bytesPerChunk * 8;
			int bitsLeft = msg.LengthBits;
			for (int i = 0; i < numChunks; i++)
			{
				NetOutgoingMessage chunk = CreateMessage(mtu);

				chunk.m_bitLength = (bitsLeft > bitsPerChunk ? bitsPerChunk : bitsLeft);
				chunk.m_data = msg.m_data;
				chunk.m_fragmentGroup = group;
				chunk.m_fragmentGroupTotalBits = totalBytes * 8;
				chunk.m_fragmentChunkByteSize = bytesPerChunk;
				chunk.m_fragmentChunkNumber = i;

				NetException.Assert(chunk.m_bitLength != 0);
				NetException.Assert(chunk.GetEncodedSize() < mtu);

				Interlocked.Add(ref chunk.m_recyclingCount, recipients.Count);

				foreach (NetConnection recipient in recipients)
					recipient.EnqueueMessage(chunk, method, sequenceChannel);

				bitsLeft -= bitsPerChunk;
			}

			return;
		}
开发者ID:Dahie,项目名称:September-1983,代码行数:51,代码来源:NetPeer.Fragmentation.cs

示例12: SendToAll

        /// <summary>
        /// Send a message to all connections except one
        /// </summary>
        /// <param name="msg">The message to send</param>
        /// <param name="method">How to deliver the message</param>
        /// <param name="except">Don't send to this particular connection</param>
        /// <param name="sequenceChannel">Which sequence channel to use for the message</param>
        public void SendToAll(NetOutgoingMessage msg, NetConnection except, NetDeliveryMethod method, int sequenceChannel)
        {
            var all = this.Connections;
            if (all.Count <= 0)
                return;

            List<NetConnection> recipients = new List<NetConnection>(all.Count - 1);
            foreach (var conn in all)
                if (conn != except)
                    recipients.Add(conn);

            if (recipients.Count > 0)
                SendMessage(msg, recipients, method, sequenceChannel);
        }
开发者ID:ncoder,项目名称:MonoGame,代码行数:21,代码来源:NetServer.cs

示例13: SendNetworkMessage

        public void SendNetworkMessage(Message message, SendTo sendTo, NetIncomingMessage netMessage = null, NetDeliveryMethod deliveryMethod = NetDeliveryMethod.ReliableOrdered)
        {
            if (m_isServer)
            {
                Type messageType = message.GetType();
                NetOutgoingMessage om = m_server.CreateMessage();
                om.Write((int)MessageFunction.ClassMessage);;
                om.Write(messageType.Assembly.ToString());
                om.Write(messageType.ToString());
                om.WriteAllFields(message);

                NetConnection sender = null;
                if (netMessage != null)
                {
                    sender = netMessage.SenderConnection;
                }

                switch (sendTo)
                {
                    case SendTo.All:
                        message.OnCalled(message, netMessage);
                        m_server.SendToAll(om, sender, deliveryMethod, 0);
                        break;
                    case SendTo.Others:
                        m_server.SendToAll(om, sender, deliveryMethod, 0);
                        if (sender != null)  //If server diden't send the message
                            message.OnCalled(message, netMessage);
                        break;
                    case SendTo.Server:
                        message.OnCalled(message, netMessage);
                        break;
                }
            }
            else
            {
                Type messageType = message.GetType();
                NetOutgoingMessage om = m_client.CreateMessage();
                om.Write((int)MessageFunction.ClassMessage);
                om.Write((int) sendTo);
                om.Write(messageType.Assembly.ToString());
                om.Write(messageType.ToString());
                om.WriteAllFields(message);
                m_client.SendMessage(om, deliveryMethod);

                if (sendTo == SendTo.All) //Trigger for sender if you sent it to everybody
                {
                    message.OnCalled(message, netMessage);
                }
            }
        }
开发者ID:Fr0sZ,项目名称:Skylines-Multiplayer,代码行数:50,代码来源:MultiplayerManager.cs

示例14: 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(INetOutgoingMessage msg, IList<INetConnection> recipients, NetDeliveryMethod method, int sequenceChannel)
        {
            NetOutgoingMessage _msg = (NetOutgoingMessage)msg;
            if (msg == null)
                throw new ArgumentNullException("msg");
            if (recipients == null)
            {
                if (_msg.m_isSent == false)
                    Recycle(_msg);
                throw new ArgumentNullException("recipients");
            }
            if (recipients.Count < 1)
            {
                if (_msg.m_isSent == false)
                    Recycle(_msg);
                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");
            _msg.m_isSent = true;

            int mtu = GetMTU(recipients);

            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.Dropped)
                        Interlocked.Decrement(ref _msg.m_recyclingCount);
                }
            }
            else
            {
                // message must be fragmented!
                SendFragmentedMessage(_msg, recipients, method, sequenceChannel);
            }

            return;
        }
开发者ID:AyyTee,项目名称:Aventyr,代码行数:56,代码来源:NetPeer.Send.cs

示例15: SendSystemNetworkMessage

        /// <summary>
        /// Sends a message to the relevant system(s) serverside.
        /// </summary>
        public void SendSystemNetworkMessage(EntitySystemMessage message,
                                             NetDeliveryMethod method = NetDeliveryMethod.ReliableUnordered)
        {
            NetOutgoingMessage newMsg = CreateEntityMessage();
            newMsg.Write((byte)EntityMessage.SystemMessage);

            var stream = new MemoryStream();
            Serializer.Serialize(stream, message);
            newMsg.Write((int)stream.Length);
            newMsg.Write(stream.ToArray());

            if (_messageProfiling)
            {
                //Log the message
            }

            //Send the message
            _networkManager.SendMessage(newMsg, method);
        }
开发者ID:millpond,项目名称:space-station-14,代码行数:22,代码来源:EntityNetworkManager.cs


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