本文整理汇总了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;
}
示例2: MessageTypeDescription
public MessageTypeDescription(ushort messageTypeId, Type messageType, int sequenceChannel, NetDeliveryMethod deliveryMethod)
{
_messageTypeId = messageTypeId;
_messageType = messageType;
_sequenceChannel = sequenceChannel;
_deliveryMethod = deliveryMethod;
}
示例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;
}
示例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"
}
}
示例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);
}
示例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.
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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);
}