public Read ( byte buffer, int offset, int count ) : int | ||
buffer | byte | |
offset | int | |
count | int | |
return | int |
using System.Net.Security; using System.IO; // 'stream' is an instance of NetworkStream obtained from a TcpClient // 'sslStream' is an instance of SslStream created from 'stream' // read data from the SslStream byte[] buffer = new byte[1024]; int bytesRead = sslStream.Read(buffer, 0, buffer.Length); // convert the data to a string and display string data = System.Text.Encoding.ASCII.GetString(buffer, 0, bytesRead); Console.WriteLine("Received data: {0}", data);
using System.Net.Security; using System.IO; // 'stream' and 'sslStream' same as previous example // create an instance of a specific encoding to use System.Text.Encoding encoding = System.Text.Encoding.UTF8; // read data from the SslStream using the specified encoding StreamReader reader = new StreamReader(sslStream, encoding); string data = reader.ReadLine(); // display the read data Console.WriteLine("Received data: {0}", data);In this example, we use an instance of StreamReader to read data from the SslStream, and specify a specific encoding to use. The data is then displayed as a string. Package/library: System.Net.Security is part of the .NET Framework Class Library, which is included with the .NET Framework runtime.
public Read ( byte buffer, int offset, int count ) : int | ||
buffer | byte | |
offset | int | |
count | int | |
return | int |