本文整理汇总了C#中NetState.GetHandler方法的典型用法代码示例。如果您正苦于以下问题:C# NetState.GetHandler方法的具体用法?C# NetState.GetHandler怎么用?C# NetState.GetHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetState
的用法示例。
在下文中一共展示了NetState.GetHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnReceive
public bool OnReceive(NetState ns)
{
ByteQueue buffer = ns.Buffer;
if (buffer == null || buffer.Length <= 0)
return true;
lock (buffer)
{
int length = buffer.Length;
while (length > 0)
{
int packetID = buffer.GetPacketID();
PacketHandler handler = ns.GetHandler(packetID);
if (handler == null)
{
byte[] data = new byte[length];
length = buffer.Dequeue(data, 0, length);
new PacketReader(data, length, false).Trace(ns);
break;
}
int packetLength = handler.Length;
if (packetLength <= 0)
{
if (length >= 3)
{
packetLength = buffer.GetPacketLength();
if (packetLength < 3)
{
ns.Dispose();
break;
}
}
else
{
break;
}
}
if (length < packetLength)
break;
byte[] packetBuffer = BufferSize >= packetLength ? _buffers.AcquireBuffer() : new byte[packetLength];
packetLength = buffer.Dequeue(packetBuffer, 0, packetLength);
PacketReader r = new PacketReader(packetBuffer, packetLength, handler.Length != 0);
handler.OnReceive(ns, r);
length = buffer.Length;
if (BufferSize >= packetLength)
_buffers.ReleaseBuffer(packetBuffer);
}
}
return true;
}