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


例外の種類 | 条件 |
---|---|
NotSupportedException | Windows 2000 以前のオペレーティング システムです。このメソッドを使用するには、Windows XP が必要です。 |
ObjectDisposedException | |
ArgumentNullException | asyncResult が null 参照 (Visual Basic では Nothing) です。 |
ArgumentException | |
InvalidOperationException | |
SocketException | |
WebException |

EndDisconnect は BeginDisconnect の呼び出しを完了します。EndDisconnect メソッドは、接続解除要求が完了するまでブロックします。非同期操作については、MSDN ライブラリで、「非同期プログラミングの概要」のトピックを参照してください。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode プロパティを使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認してください。これは MSDN ライブラリから入手できます。 |

非同期通信のソケットを作成し、リモート ホストにデータを送信するコード例を次に示します。データが送信されると、Shutdown が呼び出されて送受信の動作が停止します。次に、BeginDisconnect が呼び出されて接続解除要求を開始します。コールバック デリゲートは EndDisconnect を呼び出し、非同期要求を終了します。要求が完了すると、Connected プロパティが問い合わせを受けてソケットが接続解除されたかどうかがテストされます。
// Establish the remote endpoint for the socket. // For this example use local computer. IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); IPAddress ipAddress = ipHostInfo.AddressList[0]; IPEndPoint remoteEP = new IPEndPoint(ipAddress, 11000); // Create a TCP/IP socket. Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // Connect to the remote endpoint. client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client); // Wait for connect. connectDone.WaitOne(); // Send some data to the remote device. string data = "This is a string of data <EOF>"; byte[] buffer = Encoding.ASCII.GetBytes(data); client.BeginSend(buffer, 0, buffer.Length, 0, new AsyncCallback(ClientSendCallback), client); // Wait for send done. sendDone.WaitOne(); // Release the socket. client.Shutdown(SocketShutdown.Both); client.BeginDisconnect(true, new AsyncCallback(DisconnectCallback), client); // Wait for the disconnect to complete. disconnectDone.WaitOne(); if (client.Connected) Console.WriteLine("We're still connected"); else Console.WriteLine("We're disconnected"); } private static void DisconnectCallback(IAsyncResult ar) { // Complete the disconnect request. Socket client = (Socket) ar.AsyncState; client.EndDisconnect(ar); // Signal that the disconnect is complete. disconnectDone.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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Socket.EndDisconnect メソッドのページへのリンク