private void DataReceivedCallback(IAsyncResult ar) { NetworkStream stream = (NetworkStream)ar.AsyncState; int lidos; try { lidos = stream.EndRead(ar); } catch (ObjectDisposedException) { return; } if (lidos == 0) { return; } m_ReceiveBuffer.ConfirmWrite(lidos); ByteStream packetStream; while (DelimitedMessage.TryGetPacket(m_ReceiveBuffer, out packetStream)) { OnPacketReceived?.Invoke(this, packetStream); } m_ReceiveBuffer.Compact(); RegisterWaitData(); }
private void DataReceivedCallback(IAsyncResult ar) { NetworkStream ns = (NetworkStream)ar.AsyncState; int lidos = ns.EndRead(ar); m_ReceiveBuffer.ConfirmWrite(lidos); if (lidos == 0) { m_PacketReceived?.Invoke(this, null); EndConnection(); } ByteStream packetStream = null; while (DelimitedMessage.TryGetPacket(m_ReceiveBuffer, out packetStream)) { m_PacketReceived?.Invoke(this, packetStream); } if (packetStream != null) { m_ReceiveBuffer.Compact(); } }