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

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

TcpListener.EndAcceptTcpClient メソッド

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

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

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

Public Function EndAcceptTcpClient ( _
    asyncResult As IAsyncResult _
) As TcpClient
Dim instance As TcpListener
Dim asyncResult As IAsyncResult
Dim returnValue As TcpClient

returnValue = instance.EndAcceptTcpClient(asyncResult)
public TcpClient EndAcceptTcpClient (
    IAsyncResult asyncResult
)
public:
TcpClient^ EndAcceptTcpClient (
    IAsyncResult^ asyncResult
)
public TcpClient EndAcceptTcpClient (
    IAsyncResult asyncResult
)
public function EndAcceptTcpClient (
    asyncResult : IAsyncResult
) : TcpClient

パラメータ

asyncResult

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

戻り値
TcpClient

解説解説
使用例使用例

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

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


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


' Process the client connection.
Public Shared Sub DoAcceptTcpClientCallback(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 client As TcpClient = listener.EndAcceptTcpClient(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.
   tcpClientConnected.Set()
End Sub 'DoAcceptTcpClientCallback
 
// Thread signal.
public static ManualResetEvent tcpClientConnected
 = 
    new ManualResetEvent(false);

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

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

    // Accept the connection. 
    // BeginAcceptSocket() creates the accepted socket.
    listener.BeginAcceptTcpClient(
        new AsyncCallback(DoAcceptTcpClientCallback), 
        listener);

    // Wait until a connection is made and processed before 
    // continuing.
    tcpClientConnected.WaitOne();
}

// Process the client connection.
public static void DoAcceptTcpClientCallback(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.
    TcpClient client = listener.EndAcceptTcpClient(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.
    tcpClientConnected.Set();

}
    // Thread signal.
public:
    static ManualResetEvent^ TcpClientConnected;

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

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

        // Accept the connection.
        // BeginAcceptSocket() creates the accepted socket.
        listener->BeginAcceptTcpClient(
            gcnew AsyncCallback(DoAcceptTcpClientCallback),
            listener);

        // Wait until a connection is made and processed before
        // continuing.
        TcpClientConnected->WaitOne();
    }

    // Process the client connection.
public:
    static void DoAcceptTcpClientCallback(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.
        TcpClient^ client = listener->EndAcceptTcpClient(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.
        TcpClientConnected->Set();

    }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TcpListener クラス
TcpListener メンバ
System.Net.Sockets 名前空間



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS