SslStream.EndRead メソッドとは? わかりやすく解説

SslStream.EndRead メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

BeginRead の以前の呼び出しで開始した非同期読み取り操作を終了します。

名前空間: System.Net.Security
アセンブリ: System (system.dll 内)
構文構文

Public Overrides Function
 EndRead ( _
    asyncResult As IAsyncResult _
) As Integer
Dim instance As SslStream
Dim asyncResult As IAsyncResult
Dim returnValue As Integer

returnValue = instance.EndRead(asyncResult)
public override int EndRead (
    IAsyncResult asyncResult
)
public:
virtual int EndRead (
    IAsyncResult^ asyncResult
) override
public int EndRead (
    IAsyncResult asyncResult
)
public override function EndRead (
    asyncResult : IAsyncResult
) : int

パラメータ

asyncResult

BeginRead の呼び出しによって返される IAsyncResult インスタンス。

戻り値
基になるストリームから読み取るバイト数を指定する Int32 値。

例外例外
例外の種類条件

ArgumentNullException

asyncResult が null 参照 (Visual Basic では Nothing) です。

ArgumentException

BeginRead への呼び出しで asyncResult が作成されませんでした。

InvalidOperationException

完了する保留中の読み取り操作がありません。

IOException

読み取り操作に失敗しました。

InvalidOperationException

認証が行われていません。

解説解説

操作が完了していない場合、このメソッドは操作が完了するまでブロックします。

この操作を同期で実行するには、Read メソッドを使用します。

このメソッドは、正常に認証されるまで呼び出すことはできません。認証するには、AuthenticateAsClient、BeginAuthenticateAsClient、AuthenticateAsServer、BeginAuthenticateAsServer のいずれかのメソッドを呼び出します。

使用例使用例

非同期読み取り操作を終了するコード例を次に示します。

static void ReadCallback(IAsyncResult ar)
{
    // Read the  message sent by the server.
    // The end of the message is signaled using the
    // "<EOF>" marker.
    SslStream stream = (SslStream) ar.AsyncState;
    int byteCount = -1;
    try 
    {
        Console.WriteLine("Reading data from the server.");
        byteCount = stream.EndRead(ar);
        // 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,
 byteCount)];
        decoder.GetChars(buffer, 0, byteCount, chars,0);
        readData.Append (chars);
        // Check for EOF or an empty message.
        if (readData.ToString().IndexOf("<EOF>")
 == -1 && byteCount != 0)
        {
            // We are not finished reading.
            // Asynchronously read more message data from  the server.
            stream.BeginRead(buffer, 0, buffer.Length, 
                new AsyncCallback(ReadCallback),
                stream);
        } 
        else
        {
            Console.WriteLine("Message from the server: {0}", readData.ToString());
        }
    }
    catch (Exception readException)
    {
        e = readException;
        complete = true;
        return;
    }
    complete = true;
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SslStream クラス
SslStream メンバ
System.Net.Security 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

SslStream.EndRead メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SslStream.EndRead メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS