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

Dim instance As TcpListener Dim returnValue As Socket returnValue = instance.AcceptSocket
データの送受信に使用する Socket。


AcceptSocket は、データの送受信に使用できる Socket を返すブロッキング メソッドです。ブロックしないようにする場合は、Pending メソッドを使用して、受信接続キュー内で接続要求を使用できるかどうかを確認します。
返される Socket は、リモート ホストの IP アドレスとポート番号を使用して初期化されます。Socket クラスで利用できる任意の Send メソッドおよび Receive メソッドを使用して、リモート ホストと通信できます。Socket の使用を終了したら、必ず Close メソッドを呼び出してください。アプリケーションが比較的単純な場合は、AcceptSocket メソッドではなく AcceptTcpClient メソッドを使用することを検討してください。TcpClient は、同期ブロッキング モードのネットワーク上でデータを送受信するための単純なメソッドを提供します。
![]() |
---|
このメンバは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。詳細については、「ネットワークのトレース」を参照してください。 |

AcceptSocket メソッドを使用して、Socket を返すコード例を次に示します。この Socket は、新しく接続したクライアントとの通信に使用します。
' Accepts the pending client connection and returns a socket for communciation. Dim socket As Socket = tcpListener.AcceptSocket() Console.WriteLine("Connection accepted.") Dim responseString As String = "You have successfully connected to me" 'Forms and sends a response string to the connected client. Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(responseString) Dim i As Integer = socket.Send(sendBytes) Console.WriteLine(("Message Sent /> : " + responseString))
// Accepts the pending client connection and returns a socket for communciation. Socket socket = tcpListener.AcceptSocket(); Console.WriteLine("Connection accepted."); string responseString = "You have successfully connected to me"; //Forms and sends a response string to the connected client. Byte[] sendBytes = Encoding.ASCII.GetBytes(responseString); int i = socket.Send(sendBytes); Console.WriteLine("Message Sent /> : " + responseString);
// Accepts the pending client connection and returns a socket for communciation. Socket^ socket = tcpListener->AcceptSocket(); Console::WriteLine( "Connection accepted." ); String^ responseString = "You have successfully connected to me"; //Forms and sends a response string to the connected client. array<Byte>^sendBytes = Encoding::ASCII->GetBytes( responseString ); int i = socket->Send( sendBytes ); Console::WriteLine( "Message Sent /> : {0}", responseString );
// Accepts the pending client connection and returns a // socket for communciation. Socket socket = tcpListener.AcceptSocket(); Console.WriteLine("Connection accepted."); String responseString = "You have successfully connected to me"; // Forms and sends a response string to the connected // client. ubyte sendBytes[] = Encoding.get_ASCII().GetBytes( responseString); int i = socket.Send(sendBytes); Console.WriteLine(("Message Sent /> : " + responseString));

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


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

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