I'm wondering if there are any good guides or books that explain the best way to handle network packet communication in C#?
Right now I'm using a structure and a method that generates a byte array based on values of the structure.
Is there a simpler way to do this? Or even a better way?
public struct hotline_transaction
{
private int transaction_id;
private short task_number;
private int error_code;
private int data_length;
private int data_length2;
...
public int Transaction_id
{
get
{
return IPAddress.HostToNetworkOrder(transaction_id);
}
set
{
transaction_id = value;
}
}
...
public byte[] GetBytes()
{
List<byte> buffer = new List<byte>();
buffer.Add(0); // reserved
buffer.Add(0); // request = 0
buffer.AddRange(BitConverter.GetBytes(Task_number));
buffer.AddRange(BitConverter.GetBytes(Transaction_id));
buffer.AddRange(BitConverter.GetBytes(error_code));
buffer.AddRange(BitConverter.GetBytes(Data_length));
buffer.AddRange(subBuffer.ToArray());
return buffer.ToArray(); // return byte array for network sending
}
}
Beyond that is there a good guide or article on the best practice of parsing network data into usable structures / classes?