Person p = new Person("Tyler", "Durden", 30); // create my serializable object string serverIp = "127.0.0.1"; TcpClient client = new TcpClient(serverIp, 9050); // have my connection established with a Tcp Server IFormatter formatter = new BinaryFormatter(); // the formatter that will serialize my object on my stream NetworkStream strm = client.GetStream(); // the stream formatter.Serialize(strm, p); // the serialization process strm.Close(); client.Close();
TcpListener server = new TcpListener(9050); server.Start(); Console.WriteLine("Server ready"); TcpClient client = server.AcceptTcpClient(); NetworkStream strm = client.GetStream(); IFormatter formatter = new BinaryFormatter(); Person p = (Person)formatter.Deserialize(strm); // you have to cast the deserialized object Console.WriteLine("Hi, I'm " + p.FirstName); strm.Close(); client.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)