本文整理汇总了C#中NetDeliveryMethod类的典型用法代码示例。如果您正苦于以下问题:C# NetDeliveryMethod类的具体用法?C# NetDeliveryMethod怎么用?C# NetDeliveryMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetDeliveryMethod类属于命名空间,在下文中一共展示了NetDeliveryMethod类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: SendComponentNetworkMessage
/// <summary>
/// Allows a component owned by this entity to send a message to a counterpart component on the
/// counterpart entities on all clients.
/// </summary>
/// <param name="sendingEntity">Entity sending the message (also entity to send to)</param>
/// <param name="family">Family of the component sending the message</param>
/// <param name="method">Net delivery method -- if null, defaults to NetDeliveryMethod.ReliableUnordered</param>
/// <param name="messageParams">Parameters of the message</param>
public void SendComponentNetworkMessage(Entity sendingEntity, ComponentFamily family,
NetDeliveryMethod method = NetDeliveryMethod.ReliableUnordered,
params object[] messageParams)
{
NetOutgoingMessage message = CreateEntityMessage();
message.Write((byte)EntityMessage.ComponentMessage);
message.Write(sendingEntity.Uid); //Write this entity's UID
message.Write((byte) family);
PackParams(message, messageParams);
if (_messageProfiling)
{
//Log the message
var logger = IoCManager.Resolve<IMessageLogger>();
logger.LogOutgoingComponentNetMessage(sendingEntity.Uid, family, messageParams);
}
//Send the message
_networkManager.SendMessage(message, method);
}
开发者ID:millpond,项目名称:space-station-14,代码行数:28,代码来源:EntityNetworkManager.cs
示例17: 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, INetConnection except, NetDeliveryMethod method, int sequenceChannel)
{
var all = this.Connections;
if (all.Count <= 0) {
if (msg.m_isSent == false)
Recycle(msg);
return;
}
if (except == null)
{
SendMessage(msg, all, method, sequenceChannel);
return;
}
List<INetConnection> recipients = new List<INetConnection>(all.Count - 1);
foreach (var conn in all)
if (conn != except)
recipients.Add(conn);
if (recipients.Count > 0)
SendMessage(msg, recipients, method, sequenceChannel);
}
开发者ID:AyyTee,项目名称:Aventyr,代码行数:30,代码来源:NetServer.cs
示例18: GetSendQueueInfo
/// <summary>
/// Zero windowSize indicates that the channel is not yet instantiated (used)
/// Negative freeWindowSlots means this amount of messages are currently queued but delayed due to closed window
/// </summary>
public void GetSendQueueInfo(NetDeliveryMethod method, int sequenceChannel, out int windowSize, out int freeWindowSlots)
{
int channelSlot = (int)method - 1 + sequenceChannel;
var chan = m_sendChannels[channelSlot];
if (chan == null)
{
windowSize = NetUtility.GetWindowSize(method);
freeWindowSlots = windowSize;
return;
}
windowSize = chan.WindowSize;
freeWindowSlots = chan.GetAllowedSends() - chan.m_queuedSends.Count;
return;
}
开发者ID:DrPandemic,项目名称:EraParadox,代码行数:19,代码来源:NetConnection.cs
示例19: 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
示例20: SendMessage
/// <summary>
/// Send a message to this remote connection
/// </summary>
/// <param name="msg">The message to send</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, NetDeliveryMethod method, int sequenceChannel)
{
return m_peer.SendMessage(msg, this, method, sequenceChannel);
}
开发者ID:DrPandemic,项目名称:EraParadox,代码行数:10,代码来源:NetConnection.cs
注:本文中的NetDeliveryMethod类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论