SslStream.Read Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Přetížení
| Read(Span<Byte>) | |
| Read(Byte[], Int32, Int32) |
Načte data z tohoto datového proudu a uloží je do zadaného pole. |
Read(Span<Byte>)
- Zdroj:
- SslStream.cs
- Zdroj:
- SslStream.cs
public:
override int Read(Span<System::Byte> buffer);
public override int Read(Span<byte> buffer);
override this.Read : Span<byte> -> int
Public Overrides Function Read (buffer As Span(Of Byte)) As Integer
Parametry
Návraty
Platí pro
Read(Byte[], Int32, Int32)
- Zdroj:
- SslStream.cs
- Zdroj:
- SslStream.cs
- Zdroj:
- SslStream.cs
- Zdroj:
- SslStream.cs
Načte data z tohoto datového proudu a uloží je do zadaného pole.
public:
override int Read(cli::array <System::Byte> ^ buffer, int offset, int count);
public override int Read(byte[] buffer, int offset, int count);
override this.Read : byte[] * int * int -> int
Public Overrides Function Read (buffer As Byte(), offset As Integer, count As Integer) As Integer
Parametry
- offset
- Int32
A Int32 , který obsahuje umístění založené na nule, ve buffer kterém chcete začít ukládat data načtená z tohoto datového proudu.
Návraty
Hodnota Int32 , která určuje počet přečtených bajtů. Pokud nejsou k dispozici žádná další data ke čtení, vrátí 0.
Výjimky
buffer je null.
Hodnota offset je menší než nula.
-nebo-
offsetje větší než délka .buffer
-nebo-
offset+count je větší než délka .buffer
Operace čtení se nezdařila. Zkontrolujte vnitřní výjimku, pokud je k dispozici, a určete příčinu selhání.
Operace čtení už probíhá.
Tento objekt byl uzavřen.
K ověření nedošlo.
Příklady
Následující příklad kódu ukazuje čtení z objektu SslStream.
static string ReadMessage(SslStream sslStream)
{
// Read the message sent by the server.
// The end of the message is signaled using the
// "<EOF>" marker.
byte [] buffer = new byte[2048];
StringBuilder messageData = new StringBuilder();
int bytes = -1;
do
{
bytes = sslStream.Read(buffer, 0, buffer.Length);
// Use Decoder class to convert from bytes to UTF8
// in case a character spans two buffers.
Decoder decoder = Encoding.UTF8.GetDecoder();
char[] chars = new char[decoder.GetCharCount(buffer,0,bytes)];
decoder.GetChars(buffer, 0, bytes, chars,0);
messageData.Append (chars);
// Check for EOF.
if (messageData.ToString().IndexOf("<EOF>") != -1)
{
break;
}
} while (bytes != 0);
return messageData.ToString();
}
Private Shared Function ReadMessage(sslStream As SslStream) As String
' Read the message sent by the server.
' The end of the message is signaled using the "<EOF>" marker.
Dim buffer = New Byte(2048) {}
Dim messageData = New StringBuilder()
Dim bytes As Integer
Do
bytes = sslStream.Read(buffer, 0, buffer.Length)
' Use Decoder class to convert from bytes to UTF8
' in case a character spans two buffers.
Dim decoder As Decoder = Encoding.UTF8.GetDecoder()
Dim chars = New Char(decoder.GetCharCount(buffer, 0, bytes) - 1) {}
decoder.GetChars(buffer, 0, bytes, chars, 0)
messageData.Append(chars)
' Check for EOF.
If messageData.ToString().IndexOf("<EOF>") <> -1 Then Exit Do
Loop While bytes <> 0
Return messageData.ToString()
End Function
Poznámky
Metoda načte z datového proudu maximálně bajty count a ukládá je od bufferoffset. Nelze provést více souběžných operací čtení.
Tuto metodu nelze volat, dokud se úspěšně neověříte. K ověření zavolejte některou AuthenticateAsClientz metod , nebo BeginAuthenticateAsClient, AuthenticateAsServer. BeginAuthenticateAsServer
Pokud chcete tuto operaci provést asynchronně, použijte metodu BeginRead .