private void ReadBuffer(int read) { try { ms.Position = 0; ms.Write(buffer, 0, read); ms.Position = 0; while (ms.Position < read) { Packet p = PooledObjects.PacketPool.Pop(); //Set the session p.Session = session; //This is an unreliable packet (unless the server says something different) p.Reliable = false; try { int packetSize = Packet.DeserializeLengthDelimited(ms, ms.BinaryReader, p); p.Reliable = p.Reliable.GetValueOrDefault(false); OnPacketReceived(p, packetSize); } finally { PooledObjects.PacketPool.Push(p); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } }
internal void OnBinaryMessageReceived(byte[] message) { if (stopped) { if (socket != null) { socket.Terminate(); socket = null; } return; } BinaryWriteMemoryStream ms = new BinaryWriteMemoryStream(); int length = message.Length; ms.Write(message, 0, length); ms.Position = 0; while (ms.Position < length) { int bytesRead; Packet p = PooledObjects.PacketPool.Pop(); if (stopped) { return; } p.Session = session; p.Reliable = true; bytesRead = Packet.DeserializeLengthDelimited(ms, ms.BinaryReader, p); p.Reliable = p.Reliable.GetValueOrDefault(true); OnPacketReceived(p, bytesRead); PooledObjects.PacketPool.Push(p); } }