Sending object over TCP connection in C#

To send an object over TCP connection you have to serialize it. Let’s see an example.

[Serializable]
public class Object2Send
{
	public String Firstname { get; set; }
	public String Lastname { get; set; }
}

Send it over NetworkStream

XmlSerializer xml = new XmlSerializer(typeof(Object2Send));
if (networkStream.CanWrite)
    xml.Serialize(networkStream, Object2Send);
Categories: C# Tags: , , , ,
%d bloggers like this: