void _conn_onRecv(object sender, SocketRecvEventArgs e) { packetRecv.Add(e.GetData(), e.GetBytesReceived()); while (packetRecv.HasPacket()) { byte[] tmp = packetRecv.GetPacketBytes(); HoNRecv.Add(tmp, tmp.Length); Debug.WriteLine("--- Packet ---"); Debug.WriteLine(DebugOutput(packetRecv.GetPacket())); // For some reason, the packet length is big endian. ushort packetLength = Convert.ToUInt16(HoNRecv.ExtractBigEndianWORD()); byte packetID = HoNRecv.ExtractByte(); byte packetFamily = HoNRecv.ExtractByte(); this.HandlePacket(packetFamily, packetID); // Because only the packet is copied to the new buffer, we can advance the overall buffer // by its total length instead of depending on the individual parsing routines to work // correctly. Of course, this can be screwed up again by them removing the packet // length header. //HoNRecv.UpdateBuffer(); HoNRecv.Flush(); // Throw away the packet. packetRecv.ExtractBytes(packetLength + 2); packetRecv.UpdateBuffer(); } if (onSocketRecv != null) { onSocketRecv(sender, e); } }
protected virtual void OnRecieveData(SocketRecvEventArgs e) { if (onRecv != null) { onRecv(this, e); } }