Quote:
Originally Posted by intercsaki
I just wanted to mention, that your website is unreachable. :D
We are patient.
EDIT: While you're about rewriting the tuts, can you tell us some about using packets in C#? That would give some of us a real boost - me, for example. :)
|
Well I could give you a few tips. The easiest way to write a packet in .net is with the BinaryWriter and BinaryReader class.
Code:
byte[] packet;
using (MemoryStream memoryStream = new MemoryStream())
{
using (BinaryWriter writer = new BinaryWriter(memoryStream))
{
writer.Write((short)1);
writer.Write((short)0x5000);
writer.Write((short)0);
writer.Write((byte)1);
}
packet = memoryStream.ToArray();
}
using (MemoryStream memoryStream = new MemoryStream(packet))
{
using (BinaryReader reader = new BinaryReader(memoryStream))
{
short dataSize = reader.ReadInt16();
short opcode = reader.ReadInt16();
short securityBytes = reader.ReadInt16();
byte flag = reader.ReadByte();
Console.WriteLine("Data in packet is: {0}", dataSize);
Console.WriteLine("Opcode is: {0:X4}", opcode);
Console.WriteLine("Security bytes are: {0}", securityBytes);
Console.WriteLine("Encryption flag: {0}", flag);
}
}
This is a very small and basic example of how to write and read packets in C#. The first piece of code with the BinaryWriter created a packet and the 2nd part reads the packet we just created.
Once you have written a packet you can send it to the client or server using a Socket. You use a byte array to send and receive packets.