using System.IO; // create a MemoryStream object and write a UInt32 value MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); writer.Write((UInt32)42); // read the UInt32 value from the stream stream.Seek(0, SeekOrigin.Begin); UInt32 result = stream.ReadUInt32();
using System.Net.Sockets; using System.IO; // create a TcpClient to connect to a server TcpClient client = new TcpClient(); client.Connect("localhost", 1234); // create a NetworkStream object to read data from the server NetworkStream stream = client.GetStream(); // read a UInt32 value from the server UInt32 result = stream.ReadUInt32();In this example, we use a TcpClient object to connect to a server running on the localhost at port 1234. We then create a NetworkStream object to read data from the server, and use the ReadUInt32 method to read a UInt32 value that has been sent over the network. The StreamHandler ReadUInt32 method is part of the System.IO.BinaryReader class, which is part of the .NET Framework Class Library.