NegotiateStream.Read(Byte[], Int32, Int32) メソッド

定義

このストリームからデータを読み取り、指定した配列に格納します。Reads data from this stream and stores it in the specified array.

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 配列。A Byte array that receives the bytes read from the stream.

offset
Int32

このストリームから読み取ったデータの格納を開始する位置を示す、Int32 内のインデックス番号が 0 から始まる位置を格納する bufferA Int32 containing the zero-based location in buffer at which to begin storing the data read from this stream.

count
Int32

ストリームから読み取る最大バイト数を格納する Int32A Int32 containing the maximum number of bytes to read from the stream.

戻り値

基になるストリームから読み取るバイト数を指定する Int32 値。An Int32 value that specifies the number of bytes read from the underlying stream. 読み取るデータがこれ以上存在しない場合は 0 を返します。When there is no more data to be read, returns 0.

例外

読み取り操作に失敗しました。The read operation failed.

認証が行われていません。Authentication has not occurred.

Read(Byte[], Int32, Int32) 操作は既に実行されています。A Read(Byte[], Int32, Int32) operation is already in progress.

次のコード例は、NegotiateStreamからの読み取りを示しています。The following code example demonstrates reading from a NegotiateStream.

static void AuthenticateClient( TcpClient^ clientRequest )
{
   NetworkStream^ stream = clientRequest->GetStream();
   
   // Create the NegotiateStream.
   NegotiateStream^ authStream = gcnew NegotiateStream( stream,false );
   
   // Perform the server side of the authentication.
   authStream->AuthenticateAsServer();
   
   // Display properties of the authenticated client.
   IIdentity^ id = authStream->RemoteIdentity;
   Console::WriteLine( L"{0} was authenticated using {1}.", id->Name, id->AuthenticationType );
   
   // Read a message from the client.
   array<Byte>^buffer = gcnew array<Byte>(2048);
   int charLength = authStream->Read( buffer, 0, buffer->Length );
   String^ messageData = gcnew String( Encoding::UTF8->GetChars( buffer, 0, buffer->Length ) );
   Console::WriteLine( L"READ {0}", messageData );
   
   // Finished with the current client.
   authStream->Close();
   
   // Close the client connection.
   clientRequest->Close();
}


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 バイトを読み取り、offsetで始まる buffer に格納します。The method reads a maximum of count bytes from the current stream and stores them in buffer beginning at offset.

が正常に認証されるまで、このメソッドを呼び出すことはできません。You cannot call this method until you have successfully authenticated. 認証するには、AuthenticateAsClientBeginAuthenticateAsClientAuthenticateAsServer、または BeginAuthenticateAsServer メソッドのいずれかを呼び出します。To authenticate, call one of the AuthenticateAsClient, BeginAuthenticateAsClient, AuthenticateAsServer, or BeginAuthenticateAsServer methods.

この操作を非同期に実行するには、BeginRead メソッドを使用します。To perform this operation asynchronously, use the BeginRead method.

適用対象