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

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TcpListener.EndAcceptSocket メソッドの意味・解説 

TcpListener.EndAcceptSocket メソッド

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

受信接続試行非同期的に受け入れ新しSocket作成してリモート ホスト通信処理します

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

Public Function EndAcceptSocket ( _
    asyncResult As IAsyncResult _
) As Socket
Dim instance As TcpListener
Dim asyncResult As IAsyncResult
Dim returnValue As Socket

returnValue = instance.EndAcceptSocket(asyncResult)
public Socket EndAcceptSocket (
    IAsyncResult asyncResult
)
public:
Socket^ EndAcceptSocket (
    IAsyncResult^ asyncResult
)
public Socket EndAcceptSocket (
    IAsyncResult asyncResult
)
public function EndAcceptSocket (
    asyncResult : IAsyncResult
) : Socket

パラメータ

asyncResult

BeginAcceptSocket メソッドへの呼び出し返された IAsyncResult。

戻り値
Socket

例外例外
例外種類条件

ObjectDisposedException

基になる Socket閉じられています。

ArgumentNullException

asyncResult パラメータnull 参照 (Visual Basic では Nothing) です。

ArgumentException

BeginAcceptSocket メソッドへの呼び出しasyncResult パラメータ作成されませんでした

InvalidOperationException

EndAcceptSocket メソッドは既に呼び出されました。

SocketException

Socket へのアクセス試みているときにエラー発生しました詳細については「解説」を参照してください

解説解説
使用例使用例

BeginAcceptSocket メソッド使用してソケット作成接続を行うコード例次に示しますコールバック デリゲートEndAcceptSocket メソッド呼び出して非同期要求終了します

' Thread signal.
Public Shared clientConnected As
 New ManualResetEvent(False)


' Accept one client connection asynchronously.
Public Shared Sub DoBeginAcceptSocket(listener
 As TcpListener)
   ' Set the event to nonsignaled state.
   clientConnected.Reset()
   
   ' Start to listen for connections from a client.
   Console.WriteLine("Waiting for a connection...")
   
   ' Accept the connection. 
   ' BeginAcceptSocket() creates the accepted socket.
   listener.BeginAcceptSocket(New AsyncCallback(AddressOf
 DoAcceptSocketCallback), listener)
   ' Wait until a connection is made and processed before 
   ' continuing.
   clientConnected.WaitOne()
End Sub 'DoBeginAcceptSocket


' Process the client connection.
Public Shared Sub DoAcceptSocketCallback(ar
 As IAsyncResult)
   ' Get the listener that handles the client request.
   Dim listener As TcpListener = CType(ar.AsyncState,
 TcpListener)
   
   ' End the operation and display the received data on the
   'console.
   Dim clientSocket As Socket = listener.EndAcceptSocket(ar)
   
   ' Process the connection here. (Add the client to a 
   ' server table, read data, etc.)
   Console.WriteLine("Client connected completed")
   
   ' Signal the calling thread to continue.
   clientConnected.Set()
End Sub 'DoAcceptSocketCallback
// Thread signal.
public static ManualResetEvent clientConnected
 = 
    new ManualResetEvent(false);

// Accept one client connection asynchronously.
public static void DoBeginAcceptSocket(TcpListener
 listener)
{
    // Set the event to nonsignaled state.
    clientConnected.Reset();

    // Start to listen for connections from a client.
    Console.WriteLine("Waiting for a connection...");

    // Accept the connection. 
    // BeginAcceptSocket() creates the accepted socket.
    listener.BeginAcceptSocket(
        new AsyncCallback(DoAcceptSocketCallback), listener);
    // Wait until a connection is made and processed before 
    // continuing.
    clientConnected.WaitOne();
}

// Process the client connection.
public static void DoAcceptSocketCallback(IAsyncResult
 ar) 
{
    // Get the listener that handles the client request.
    TcpListener listener = (TcpListener) ar.AsyncState;
    
    // End the operation and display the received data on the
    //console.
    Socket clientSocket = listener.EndAcceptSocket(ar);
    
    // Process the connection here. (Add the client to a 
    // server table, read data, etc.)
    Console.WriteLine("Client connected completed");

    // Signal the calling thread to continue.
    clientConnected.Set();
}
    // Thread signal.
public:
    static ManualResetEvent^ ClientConnected;

    // Accept one client connection asynchronously.
public:
    static void DoBeginAcceptSocket(TcpListener^
 listener)
    {
        // Set the event to nonsignaled state.
        ClientConnected->Reset();

        // Start to listen for connections from a client.
        Console::WriteLine("Waiting for a connection...");

        // Accept the connection.
        // BeginAcceptSocket() creates the accepted socket.
        listener->BeginAcceptSocket(
            gcnew AsyncCallback(DoAcceptSocketCallback), listener);
        // Wait until a connection is made and processed before
        // continuing.
        ClientConnected->WaitOne();
    }

    // Process the client connection.
public:
    static void DoAcceptSocketCallback(IAsyncResult^
 result)
    {
        // Get the listener that handles the client request.
        TcpListener^ listener = (TcpListener^) result->AsyncState;

        // End the operation and display the received data on the
        //console.
        Socket^ clientSocket = listener->EndAcceptSocket(result);

        // Process the connection here. (Add the client to a
        // server table, read data, etc.)
        Console::WriteLine("Client connected completed");

        // Signal the calling thread to continue.
        ClientConnected->Set();
    }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TcpListener クラス
TcpListener メンバ
System.Net.Sockets 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からTcpListener.EndAcceptSocket メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からTcpListener.EndAcceptSocket メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からTcpListener.EndAcceptSocket メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

   

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



TcpListener.EndAcceptSocket メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS