本文整理汇总了C#中UDPPacketBuffer类的典型用法代码示例。如果您正苦于以下问题:C# UDPPacketBuffer类的具体用法?C# UDPPacketBuffer怎么用?C# UDPPacketBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UDPPacketBuffer类属于命名空间,在下文中一共展示了UDPPacketBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OutgoingPacket
/// <summary>
/// Default constructor
/// </summary>
/// <param name="client">Reference to the client this packet is destined for</param>
/// <param name="buffer">Serialized packet data. If the flags or sequence number
/// need to be updated, they will be injected directly into this binary buffer</param>
/// <param name="category">Throttling category for this packet</param>
public OutgoingPacket(LLUDPClient client, UDPPacketBuffer buffer, ThrottleOutPacketType category, UnackedPacketMethod method)
{
Client = client;
Buffer = buffer;
Category = category;
UnackedMethod = method;
}
示例2: AsyncBeginReceive
private void AsyncBeginReceive()
{
lock (typeof(Constants))
{
if (!Constants.isClosing)
{
// allocate a packet buffer
UDPPacketBuffer buf = new UDPPacketBuffer();
try
{
// kick off an async read
udpSocket.BeginReceiveFrom(
buf.Data,
0,
UDPPacketBuffer.BUFFER_SIZE,
SocketFlags.None,
ref buf.RemoteEndPoint,
new AsyncCallback(AsyncEndReceive),
buf);
}
catch (SocketException se)
{
txtReceive.Text = se.Message + System.Environment.NewLine + txtReceive.Text;
}
}
}
}
示例3: OutgoingPacket
/// <summary>
/// Default constructor
/// </summary>
/// <param name="client">Reference to the client this packet is destined for</param>
/// <param name="buffer">Serialized packet data. If the flags or sequence number
/// need to be updated, they will be injected directly into this binary buffer</param>
/// <param name="category">Throttling category for this packet</param>
/// <param name="resendMethod">The delegate to be called if this packet is determined to be unacknowledged</param>
/// <param name="finishedMethod">The delegate to be called when this packet is sent</param>
public OutgoingPacket(LLUDPClient client, UDPPacketBuffer buffer,
ThrottleOutPacketType category, UnackedPacketMethod resendMethod,
UnackedPacketMethod finishedMethod, Packet packet)
{
Client = client;
Buffer = buffer;
Category = category;
UnackedMethod = resendMethod;
FinishedMethod = finishedMethod;
Packet = packet;
}
示例4: SendPacketData
public void SendPacketData(byte[] data, int dataLength, PacketType type, bool doZerocode)
{
UDPPacketBuffer buffer = new UDPPacketBuffer(remoteEndPoint, Packet.MTU);
// Zerocode if needed
if (doZerocode)
{
try { dataLength = Helpers.ZeroEncode(data, dataLength, buffer.Data); }
catch (IndexOutOfRangeException)
{
// The packet grew larger than Packet.MTU bytes while zerocoding.
// Remove the MSG_ZEROCODED flag and send the unencoded data
// instead
data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
}
}
else
{
Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
}
buffer.DataLength = dataLength;
#region Queue or Send
NetworkManager.OutgoingPacket outgoingPacket = new NetworkManager.OutgoingPacket(this, buffer);
// Send ACK and logout packets directly, everything else goes through the queue
if (Client.Settings.THROTTLE_OUTGOING_PACKETS == false ||
type == PacketType.PacketAck ||
type == PacketType.LogoutRequest)
{
SendPacketFinal(outgoingPacket);
}
else
{
Network.PacketOutbox.Enqueue(outgoingPacket);
}
#endregion Queue or Send
#region Stats Tracking
if (Client.Settings.TRACK_UTILIZATION)
{
Client.Stats.Update(type.ToString(), OpenMetaverse.Stats.Type.Packet, dataLength, 0);
}
#endregion
}
示例5: PacketSent
protected override void PacketSent(UDPPacketBuffer buffer, int bytesSent)
{
// Stats tracking
Interlocked.Add(ref Stats.SentBytes, bytesSent);
Interlocked.Increment(ref Stats.SentPackets);
Client.Network.RaisePacketSentEvent(buffer.Data, bytesSent, this);
}
示例6: PacketSent
protected abstract void PacketSent(UDPPacketBuffer buffer, int bytesSent);
示例7: AsyncBeginSend
public void AsyncBeginSend(UDPPacketBuffer buf)
{
rwLock.AcquireReaderLock(-1);
if (!shutdownFlag)
{
try
{
Interlocked.Increment(ref rwOperationCount);
udpSocket.BeginSendTo(
buf.Data,
0,
buf.DataLength,
SocketFlags.None,
buf.RemoteEndPoint,
new AsyncCallback(AsyncEndSend),
buf);
}
catch (SocketException)
{
//Logger.Log(
// "A SocketException occurred in UDPServer.AsyncBeginSend()",
// Helpers.LogLevel.Error, se);
}
}
rwLock.ReleaseReaderLock();
}
示例8: SendAckImmediate
public virtual void SendAckImmediate(IPEndPoint remoteEndpoint, PacketAckPacket ack)
{
byte[] packetData = ack.ToBytes();
int length = packetData.Length;
UDPPacketBuffer buffer = new UDPPacketBuffer(remoteEndpoint, length);
buffer.DataLength = length;
Buffer.BlockCopy(packetData, 0, buffer.Data, 0, length);
AsyncBeginSend(buffer);
}
示例9: SendAckImmediate
private void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber)
{
PacketAckPacket ack = new PacketAckPacket();
ack.Header.Reliable = false;
ack.Packets = new PacketAckPacket.PacketsBlock[1];
ack.Packets[0] = new PacketAckPacket.PacketsBlock();
ack.Packets[0].ID = sequenceNumber;
byte[] packetData = ack.ToBytes();
int length = packetData.Length;
UDPPacketBuffer buffer = new UDPPacketBuffer(remoteEndpoint, length);
buffer.DataLength = length;
Buffer.BlockCopy(packetData, 0, buffer.Data, 0, length);
// AsyncBeginSend(buffer);
SyncSend(buffer);
}
示例10: AsyncBeginReceive
private void AsyncBeginReceive()
{
// allocate a packet buffer
//WrappedObject<UDPPacketBuffer> wrappedBuffer = Pool.CheckOut();
UDPPacketBuffer buf = new UDPPacketBuffer();
if (!m_shutdownFlag)
{
try
{
// kick off an async read
m_udpSocket.BeginReceiveFrom(
//wrappedBuffer.Instance.Data,
buf.Data,
0,
UDPPacketBuffer.BUFFER_SIZE,
SocketFlags.None,
ref buf.RemoteEndPoint,
AsyncEndReceive,
//wrappedBuffer);
buf);
}
catch (SocketException e)
{
if (e.SocketErrorCode == SocketError.ConnectionReset)
{
m_log.Warn("[UDPBASE]: SIO_UDP_CONNRESET was ignored, attempting to salvage the UDP listener on port " + m_udpPort);
bool salvaged = false;
while (!salvaged)
{
try
{
m_udpSocket.BeginReceiveFrom(
//wrappedBuffer.Instance.Data,
buf.Data,
0,
UDPPacketBuffer.BUFFER_SIZE,
SocketFlags.None,
ref buf.RemoteEndPoint,
AsyncEndReceive,
//wrappedBuffer);
buf);
salvaged = true;
}
catch (SocketException) { }
catch (ObjectDisposedException) { return; }
}
m_log.Warn("[UDPBASE]: Salvaged the UDP listener on port " + m_udpPort);
}
}
catch (ObjectDisposedException) { }
}
}
示例11: PacketBuildingFinished
/// <summary>
/// Called when the packet is built and this buffer is no longer in use
/// </summary>
/// <param name="buffer"></param>
protected void PacketBuildingFinished(UDPPacketBuffer buffer)
{
buffer.ResetEndpoint();
_recvBufferPool.ReturnObject(buffer);
}
示例12: SendPacketData
public void SendPacketData(byte[] data, int dataLength, PacketType type, bool doZerocode)
{
UDPPacketBuffer buffer = new UDPPacketBuffer(remoteEndPoint, Packet.MTU);
// Zerocode if needed
if (doZerocode)
{
try { dataLength = Helpers.ZeroEncode(data, dataLength, buffer.Data); }
catch (IndexOutOfRangeException)
{
// The packet grew larger than Packet.MTU bytes while zerocoding.
// Remove the MSG_ZEROCODED flag and send the unencoded data
// instead
data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
}
}
else
{
Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
}
buffer.DataLength = dataLength;
#region Queue or Send
NetworkManager.OutgoingPacket outgoingPacket = new NetworkManager.OutgoingPacket(this, buffer);
// Send ACK and logout packets directly, everything else goes through the queue
if (Network.ThrottleOutgoingPackets == false ||
type == PacketType.PacketAck ||
type == PacketType.LogoutRequest)
{
SendPacketFinal(outgoingPacket);
}
else
{
Network.PacketOutbox.Enqueue(outgoingPacket);
}
#endregion Queue or Send
}
示例13: AsyncBeginSend
public void AsyncBeginSend(UDPPacketBuffer buf)
{
if (!m_shutdownFlag)
{
try
{
m_udpSocket.BeginSendTo(
buf.Data,
0,
buf.DataLength,
SocketFlags.None,
buf.RemoteEndPoint,
AsyncEndSend,
buf);
}
catch (SocketException) { }
catch (ObjectDisposedException) { }
}
}
示例14: OutgoingPacket
public OutgoingPacket(Simulator simulator, UDPPacketBuffer buffer, PacketType type)
{
Simulator = simulator;
Buffer = buffer;
this.Type = type;
}
示例15: SendPacketData
public void SendPacketData(LLUDPClient udpClient, byte[] data, Packet packet, ThrottleOutPacketType category, UnackedPacketMethod resendMethod, UnackedPacketMethod finishedMethod)
{
int dataLength = data.Length;
bool doZerocode = (data[0] & Helpers.MSG_ZEROCODED) != 0;
bool doCopy = true;
// Frequency analysis of outgoing packet sizes shows a large clump of packets at each end of the spectrum.
// The vast majority of packets are less than 200 bytes, although due to asset transfers and packet splitting
// there are a decent number of packets in the 1000-1140 byte range. We allocate one of two sizes of data here
// to accomodate for both common scenarios and provide ample room for ACK appending in both
int bufferSize = dataLength * 2;
UDPPacketBuffer buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize);
// Zerocode if needed
if (doZerocode)
{
try
{
dataLength = Helpers.ZeroEncode(data, dataLength, buffer.Data);
doCopy = false;
}
catch (IndexOutOfRangeException)
{
// The packet grew larger than the bufferSize while zerocoding.
// Remove the MSG_ZEROCODED flag and send the unencoded data
// instead
m_log.Info("[LLUDPSERVER]: Packet exceeded buffer size during zerocoding for " + packet.Type + ". DataLength=" + dataLength +
" and BufferLength=" + buffer.Data.Length + ". Removing MSG_ZEROCODED flag");
data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
}
}
// If the packet data wasn't already copied during zerocoding, copy it now
if (doCopy)
{
if (dataLength <= buffer.Data.Length)
{
Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
}
else
{
bufferSize = dataLength;
buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize);
// m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" +
// type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length + ". Dropping packet");
Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
}
}
buffer.DataLength = dataLength;
#region Queue or Send
OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, resendMethod, finishedMethod, packet);
if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket))
SendPacketFinal(outgoingPacket);
#endregion Queue or Send
}