NegotiateStream.Read(Byte[], Int32, Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從這個數據流讀取數據,並將它儲存在指定的陣列中。
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。
例外狀況
讀取操作失敗了。
尚未進行認證。
範例
以下程式碼範例示範從 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 方法。