NegotiateStream.Read(Byte[], Int32, Int32) 메서드

정의

이 스트림에서 데이터를 읽고 지정된 배열에 저장합니다.

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부터 buffer 시작)를 포함하는 위치입니다.

count
Int32

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

반품

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

예외

읽기 작업이 실패했습니다.

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

Read(Byte[], Int32, Int32) 작업이 이미 진행 중입니다.

예제

다음 코드 예제에서는 .에서 읽는 방법을 보여 줍니다 NegotiateStream.

public static void AuthenticateClient(TcpClient clientRequest)
{
    NetworkStream stream = clientRequest.GetStream();
    // Create the NegotiateStream.
    NegotiateStream authStream = new NegotiateStream(stream, false);
    // Perform the server side of the authentication.
    authStream.AuthenticateAsServer();
    // Display properties of the authenticated client.
    IIdentity id = authStream.RemoteIdentity;
    Console.WriteLine("{0} was authenticated using {1}.",
        id.Name,
        id.AuthenticationType
        );
    // Read a message from the client.
    byte [] buffer = new byte[2048];
    int charLength = authStream.Read(buffer, 0, buffer.Length);
    string messageData = new String(Encoding.UTF8.GetChars(buffer, 0, buffer.Length));

    Console.WriteLine("READ {0}", messageData);
    // Finished with the current client.
    authStream.Close();
    // Close the client connection.
    clientRequest.Close();
}

설명

메서드는 현재 스트림에서 최대 count 바이트를 읽고 처음부터 buffer저장 offset 합니다.

성공적으로 인증될 때까지 이 메서드를 호출할 수 없습니다. 인증하려면 , , AuthenticateAsClient, AuthenticateAsClientAsyncBeginAuthenticateAsClientAuthenticateAsServer또는 AuthenticateAsServerAsync 메서드 중 BeginAuthenticateAsServer하나를 호출합니다.

이 작업을 비동기적으로 수행하려면 메서드를 ReadAsync 사용합니다.

적용 대상