Quote:
Originally Posted by badguy4you
So is the way i am sending and receiving the message at my topic wrong ? also i wonder when you mention a packet it is going to be something like
A0 E7 T3 E4 E6 ....
When i mention a packet i think it is
Encoding.ASCII.GetBytes("ID:MESSAGE");
THEN
Encoding.ASCII.GetString(buffer).Spilit(':')[0]; //ID
Encoding.ASCII.GetString(buffer).Spilit(':')[1]; //Message
i am totally confused how could i send data from my client and then determine which thing i have received on the server
Like
Code:
if(packet.id == 5001) //Do some stuff;
|
Quote:
|
Originally Posted by badguy4you
Quote:
Originally Posted by I don't have a username
Take a look at the socket tutorial I've posted (Link in my signature).
Also maybe take a look at the source of Buu (My packet analyzer / proxy).
|
So is the way i am sending and receiving the message at my topic wrong ? also i wonder when you mention a packet is is going to be something like
A0 E7 T3 E4 E6 ....
When i mention a packet i think it is
Encoding.ASCII.GetString(buffer);
i am totally confused how could i send data from my client and then determine which thing i have received on the server
Like
Code:
if(packet.id == 5001) //Do some staff;
Please i need your help with that because i completely lost

|
I don't really get it... The first thing:
That's a packet dump. Each value you see there is the bytes in your packet, but converted to hex.
This:
Code:
Encoding.ASCII.GetString(buffer);
is converting the bytes to a string. It's equal to:
Code:
string s = "";
foreach (byte b in buffer)
s += (char)b;
^ StringBuilder would be better here thought, but this is just for you to understand.
To get this:
Code:
if(packet.id == 5001)
You'd have to read the actual values in the packet ex. for conquer the id is an ushort.
An ushort is 2 bytes.
The first 4 bytes is 2 ushorts which is size and id in CO.
That would make it like this:
Code:
size = buffer[0] & buffer[1]
id = buffer[2] & buffer[3]
You'd have to combine those two bytes to a single value. I'd recommend pointers for this.
Ex.
Code:
public ushort ReadUInt16(int offset)
{
return (*(ushort*)(bufferPointer + offset));
}
Now the above code won't work because you have to specify a pointer.
Code:
public byte* bufferPointer
{
get
{
fixed (byte* Ptr = buffer)
return Ptr;
}
}
Notice this rquires "allow unsafe coding".
Go to properties -> build and then check the checkbox.
Uhmm... I figure you already have a packetwriter/packetreader, so the above is just to get an understanding.