語言

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

A Int32 包含以零為 buffer 基礎的位置,從此串流開始儲存讀取資料。

count
Int32

A Int32 包含從串流中可讀取的最大位元組數。

傳回

一個 Int32 指定從底層串流讀取的位元組數的值。 當沒有更多資料可讀取時,回傳 0。

例外狀況

讀取操作失敗了。

尚未進行認證。

範例

以下程式碼範例示範從 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、 AuthenticateAsClientAsync、 BeginAuthenticateAsClient、 AuthenticateAsServerAuthenticateAsServerAsync、 或 BeginAuthenticateAsServer 方法。

若要非同步執行此操作,請使用該 ReadAsync 方法。

適用於