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

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

TcpListener.BeginAcceptSocket メソッド

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

受信接続試行受け入れ非同期操作開始します

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

Public Function BeginAcceptSocket ( _
    callback As AsyncCallback, _
    state As Object _
) As IAsyncResult
Dim instance As TcpListener
Dim callback As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginAcceptSocket(callback, state)
public IAsyncResult BeginAcceptSocket (
    AsyncCallback callback,
    Object state
)
public:
IAsyncResult^ BeginAcceptSocket (
    AsyncCallback^ callback, 
    Object^ state
)
public IAsyncResult BeginAcceptSocket (
    AsyncCallback callback, 
    Object state
)
public function BeginAcceptSocket (
    callback : AsyncCallback, 
    state : Object
) : IAsyncResult

パラメータ

callback

操作完了時に呼び出すメソッド参照する AsyncCallback デリゲート

state

受け入れ操作に関する情報格納するユーザー定義のオブジェクト。このオブジェクトは、操作完了時に callback デリゲート渡されます。

戻り値
Socket非同期作成参照する IAsyncResult。

例外例外
解説解説
使用例使用例

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 名前空間



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS