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

Dim instance As TcpListener Dim asyncResult As IAsyncResult Dim returnValue As Socket returnValue = instance.EndAcceptSocket(asyncResult)
戻り値
Socket。


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

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

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.EndAcceptSocket メソッドを検索する場合は、下記のリンクをクリックしてください。

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