Bagikan melalui


IPGlobalProperties.GetActiveTcpConnections Metode

Definisi

Mengembalikan informasi tentang koneksi Protokol Internet versi 4 (IPv4) dan Protokol Kendali Transmisi (TCP) IPv6 pada komputer lokal.

public:
 abstract cli::array <System::Net::NetworkInformation::TcpConnectionInformation ^> ^ GetActiveTcpConnections();
public abstract System.Net.NetworkInformation.TcpConnectionInformation[] GetActiveTcpConnections ();
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
public abstract System.Net.NetworkInformation.TcpConnectionInformation[] GetActiveTcpConnections ();
abstract member GetActiveTcpConnections : unit -> System.Net.NetworkInformation.TcpConnectionInformation[]
[<System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
abstract member GetActiveTcpConnections : unit -> System.Net.NetworkInformation.TcpConnectionInformation[]
Public MustOverride Function GetActiveTcpConnections () As TcpConnectionInformation()

Mengembalikan

Array TcpConnectionInformation yang berisi objek yang menjelaskan koneksi TCP aktif, atau array kosong jika tidak ada koneksi TCP aktif yang terdeteksi.

Atribut

Pengecualian

Fungsi Win32 GetTcpTable gagal.

Contoh

Contoh berikut menampilkan informasi titik akhir untuk koneksi TCP aktif.

void ShowActiveTcpConnections()
{
   Console::WriteLine( "Active TCP Connections" );
   IPGlobalProperties ^ properties = IPGlobalProperties::GetIPGlobalProperties();
   array<TcpConnectionInformation^>^connections = properties->GetActiveTcpConnections();
   System::Collections::IEnumerator^ myEnum6 = connections->GetEnumerator();
   while ( myEnum6->MoveNext() )
   {
      TcpConnectionInformation ^ c = safe_cast<TcpConnectionInformation ^>(myEnum6->Current);
      Console::WriteLine( "{0} <==> {1}", c->LocalEndPoint, c->RemoteEndPoint );
   }
}
public static void ShowActiveTcpConnections()
{
           Console.WriteLine("Active TCP Connections");
           IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
           TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
           foreach (TcpConnectionInformation c in connections)
           {
               Console.WriteLine("{0} <==> {1}",
                   c.LocalEndPoint.ToString(),
                   c.RemoteEndPoint.ToString());
           }
}

Keterangan

Objek yang dikembalikan oleh metode ini mencakup koneksi di semua status TCP kecuali status Listen . Anda dapat memeriksa status koneksi dengan memanggil State.

Protokol TCP didefinisikan dalam IETF RFC 793. Perhatikan bahwa objek yang dikembalikan oleh metode ini mencerminkan koneksi pada saat array dibuat. Informasi ini tidak diperbarui secara dinamis.

Berlaku untuk