Below I have some code that I use to handle incoming socket data, this is not full thing but its the part I am worried about, is there any way to improve this?
int packetPosition = 0;
while (packetPosition < packetData.Length)
{
try
{
int MessageLength = Apple.Encoding.DecodeInt32(new byte[] { packetData[packetPosition++], packetData[packetPosition++], packetData[packetPosition++] });
uint MessageId = Apple.Encoding.DecodeUInt32(new byte[] { packetData[packetPosition++], packetData[packetPosition++] });
byte[] Content = new byte[MessageLength - 2];
for (int i = 0; i < Content.Length && packetPosition < packetData.Length; i++)
{
Content[i] = packetData[packetPosition++];
}
IncomingPacket incomingPacket = new IncomingPacket(MessageId, Content);
}
catch (Exception e)
{
_log.Error(e);
Apple.Game.PlayerManager.DisposePlayer(_playerData.PlayerId);
}
}
full thing
. It'd make this much easier to understand and therefore help you! :) – TopinFrassi Oct 29 '15 at 18:57int MessageLength
,uint MessageId
,byte[] Content
), especially since you're not even consistent about it (int packetPosition
,IncomingPacket incomingPacket
). – Konrad Morawski Oct 29 '15 at 21:20