SslStream.Read 메서드

정의

오버로드

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

매개 변수

buffer
Span<Byte>

메모리 영역입니다. 이 메서드가 반환되면 이 지역의 내용이 현재 원본에서 읽은 바이트로 바뀝니다.

반품

버퍼에 읽은 총 바이트 수입니다. 현재 많은 바이트를 사용할 수 없는 경우 버퍼 크기보다 작을 수 있고, 버퍼의 길이가 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

매개 변수

buffer
Byte[]

Byte 이 스트림에서 읽은 바이트를 받는 배열입니다.

offset
Int32

이 스트림에서 읽은 데이터 저장을 시작할 위치Int32(0부터 시작)를 포함하는 A buffer 입니다.

count
Int32

이 스트림에서 읽을 최대 바이트 수를 포함하는 A Int32 입니다.

반품

Int32 읽은 바이트 수를 지정하는 값입니다. 읽을 데이터가 더 이상 없으면 0을 반환합니다.

예외

buffernull입니다.

offset가 0보다 작습니다.

-또는-

offset 가 .의 buffer길이보다 큰 경우

-또는-

offset+ 개수가 .buffer

읽기 작업이 실패했습니다. 내부 예외(있는 경우)를 확인하여 오류의 원인을 확인합니다.

이미 읽기 작업이 진행 중입니다.

이 개체가 닫혔습니다.

인증이 발생하지 않았습니다.

예제

다음 코드 예제에서는 .에서 읽는 방법을 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 사용합니다.

적용 대상