I'm writing an application that uses protocol buffers C #. I need some example of how to send and receive data via TCP. Especially, how to determine which type of package has arrived. I have classes:
[ProtoContract]
class Package1
{
//fields
}
[ProtoContract]
class Package2
{
//fields
}
and methods for writing to stream
private static void SendPackage(Stream stream, Package1 package)
{
Serializer.Serialize<Package1>(stream, package);
}
private static void SendPackage(Stream stream, Package2 package)
{
Serializer.Serialize<Package2>(stream, package);
}
Now, how to determine which type of package has arrived?
using (NetworkStream stream = client.GetStream())
{
switch(packageType)
{
//deserialize package
}
}
P.S sorry for my bad english.