Packet Handling Ways

01/14/2012 14:50 shadowman123#1
well im interested in packet and i seen alot of examples of building packets so here is some examples

Heres Example of Attack Packets : 1st Example

Code:
public Attack(bool Create)
        {
            if (Create)
            {
                Buffer = new byte[8 + 40];
                Writer.WriteUInt16(40, 0, Buffer);
                Writer.WriteUInt16(1022, 2, Buffer);
            }
        }
2nd Example

Code:
public Attack(bool Create)
        {
            if (Create)
            {
                Buffer = new byte[48];
                Writer.WriteUInt16(40, 0, Buffer);
                Writer.WriteUInt16(1022, 2, Buffer);
            }
        }
3rd Example

Code:
public Attack(bool Create)
        {
            if (Create)
            {
                Buffer = new byte[48];
                Writer.WriteUInt16(Buffer.Length - 8, 0, Buffer);
                Writer.WriteUInt16(1022, 2, Buffer);
            }
        }
So which one sends packets faster and which way is the best ot they all the same ??

And when should i use smthing like that

Code:
public uint Attacker
        {
            get { return BitConverter.ToUInt32(Buffer, 8); }
            set { Writer.WriteUInt32(value, 8, Buffer); }
        }

        public uint Attacked
        {
            get { return BitConverter.ToUInt32(Buffer, 12); }
            set { Writer.WriteUInt32(value, 12, Buffer); }
        }
        public Conquer_Online_Server.Network.GamePackets.SpellUse.EffectValue FirstEffect
        {
            get { return (Conquer_Online_Server.Network.GamePackets.SpellUse.EffectValue)Buffer[32]; }
            set { Writer.WriteByte((byte)value, 32, Buffer); }
        }
the last number called offset ..Right ?? anyways y the uint attacked have last number 12 not smthing else and same for effect value it contains number 32 at last ...

Code:
public AttackEffects1 Effect1
        {
            get { return (AttackEffects1)Buffer[32]; }
            set { Buffer[32] = (Byte)value; }
        }
(Conquer_Online_Server.Network.GamePackets.SpellUse.EffectValue)Buffer[32]; }
            set { Writer.WriteByte((byte)value, 32, Buffer); }
        }
Which one of them would be better to use and Which one is sent faster ?
01/16/2012 07:27 I don't have a username#2
1. Not really any difference in speed.

2. Yes the last number is 'offset', but you need to understand what it means, because it doesn't necessary need to be known as offset, because it could be position as well. Offset it just the name most use. Offset basically just means the location within the buffer, so that's the location in the buffer you would like to write.

3. Same as 1 I guess, didn't quite get it,
01/16/2012 07:54 pro4never#3
I like how you're talking about 'different ways of writing packets' and then show three examples that are identical.

The only thing you changed is the order in which you do some math.


As I said in your other thread... you need to understand what packets are better before you worry about this stuff.

Note: Video sucks it's just me showing a few 'common' ways of structuring packets as well as a bit of info on how to interpret the ACTUAL packet data. The better reference would be found as links in......
[Only registered and activated users can see links. Click Here To Register...]
01/16/2012 10:05 Arco.#4
I'll be the first to bluntly point out, this thread has nothing to do with packet handling.
01/16/2012 14:28 shadowman123#5
well i meant packet building ways Not handling you r right there is nothing about handling ways Rofl
01/17/2012 08:09 Nullable#6
lol'd @ faster/best...

[almost offtopic rant]
These simple micro-optimizations aren't going to be any helpful in the long run, you don't change the way you construct a packet to another way simply because the other one is a little bit faster, i.e. it doesn't really matter in the end if you use pointers to fill up the packet vs. BinaryWriter or anything similar. Think big changes, get out of the raw performance mindset already. That, however, doesn't mean that you shouldn't pay attention to these micro-optimizations, it just means that they should NEVER be your top priority.
[/almost offtopic rant]