Dirk,
I would serialize the thing and then send that array of bytes over the
network.
First, declare your structure as serializable:
[Serializable]
struct Packet
{
string Command;
string[] Args;
byte[] Data;
}
When you want to send it, serialize it to a MemoryStream, and get the
array of bytes:
private static byte[] SerializeToByte Array(object graph)
{
// Create a memory stream, and serialize.
using (MemoryStream stream = new MemoryStream())
{
// Create a binary formatter.
IFormatter formatter = new BinaryFormatter ();
// Serialize.
formatter.Seria lize(stream, graph);
// Now return the array.
return stream.ToArray( );
}
}
You can then send that array of bytes over the socket. To reverse the
process, just deserialize the array. I would place a length descriptor
before the content, so you know how much to read.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard. caspershouse.co m
"Dirk Reske" <_F*******@gmx. net> wrote in message
news:O8******** *****@TK2MSFTNG P09.phx.gbl...
Hey,
I have following struct:
struct Packet
{
string Command;
string[] Args;
byte[] Data;
}
how can I send (and receive) this throug a network? (some example code)
thx