TcpListener.EndAcceptTcpClient メソッド
アセンブリ: System (system.dll 内)

Dim instance As TcpListener Dim asyncResult As IAsyncResult Dim returnValue As TcpClient returnValue = instance.EndAcceptTcpClient(asyncResult)
戻り値
TcpClient。

このメソッドは、操作が完了するまでブロックします。この操作を同期的に実行するには、AcceptTcpClient メソッドを使用します。
![]() |
---|
基になるソケット (Client) の RemoteEndPoint プロパティを呼び出すと、リモート ホストのネットワーク アドレスとポート番号を確認できます。 |

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(); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からTcpListener.EndAcceptTcpClient メソッドを検索する場合は、下記のリンクをクリックしてください。

- TcpListener.EndAcceptTcpClient メソッドのページへのリンク