SslStream.Read 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| Read(Span<Byte>) |
파생 클래스에서 재정의되는 경우 현재 스트림에서 바이트 시퀀스를 읽고 읽은 바이트 수만큼 스트림 내의 위치를 앞으로 이동합니다. |
| Read(Byte[], Int32, Int32) |
이 스트림에서 데이터를 읽고 지정된 배열에 저장합니다. |
Read(Span<Byte>)
- Source:
- SslStream.cs
- Source:
- SslStream.cs
- Source:
- 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
매개 변수
반품
버퍼에 읽은 총 바이트 수입니다. 현재 많은 바이트를 사용할 수 없는 경우 버퍼 크기보다 작을 수 있고, 버퍼의 길이가 0이거나 스트림 끝에 도달한 경우 0일 수 있습니다.
적용 대상
Read(Byte[], Int32, Int32)
- Source:
- SslStream.cs
- Source:
- SslStream.cs
- Source:
- SslStream.cs
- Source:
- SslStream.cs
- Source:
- SslStream.cs
이 스트림에서 데이터를 읽고 지정된 배열에 저장합니다.
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
매개 변수
반품
Int32 읽은 바이트 수를 지정하는 값입니다. 읽을 데이터가 더 이상 없으면 0을 반환합니다.
예외
buffer은 null입니다.
읽기 작업이 실패했습니다. 내부 예외(있는 경우)를 확인하여 오류의 원인을 확인합니다.
이미 읽기 작업이 진행 중입니다.
이 개체가 닫혔습니다.
인증이 발생하지 않았습니다.
예제
다음 코드 예제에서는 .에서 읽는 방법을 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
설명
이 메서드는 스트림에서 최대 count 바이트를 읽고 처음부터 buffer저장 offset 합니다. 여러 동시 읽기 작업을 수행할 수 없습니다.
성공적으로 인증될 때까지 이 메서드를 호출할 수 없습니다. 또는 , AuthenticateAsClientBeginAuthenticateAsClientAuthenticateAsServer 메서드 중 BeginAuthenticateAsServer하나를 호출하도록 인증합니다.
이 작업을 비동기적으로 수행하려면 메서드를 BeginRead 사용합니다.