IPGlobalProperties.GetActiveUdpListeners 方法

定義

傳回本機電腦上之網際網路通訊協定第 4 版 (IPv4) 和 IPv6 使用者資料包通訊協定 (User Datagram Protocol,UDP) 接聽程式的相關資訊。

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

傳回

IPEndPoint 陣列,包含描述 UDP 接聽程式的物件,但如果沒有偵測到 UDP 接聽程式則為空陣列。

屬性

例外狀況

呼叫 Win32 函式 GetUdpTable 失敗。

範例

下列範例會顯示作用中的UDP接聽程式。

void ShowActiveUdpListeners()
{
   Console::WriteLine( "Active UDP Listeners" );
   IPGlobalProperties ^ properties = IPGlobalProperties::GetIPGlobalProperties();
   array<IPEndPoint^>^endPoints = properties->GetActiveUdpListeners();
   System::Collections::IEnumerator^ myEnum8 = endPoints->GetEnumerator();
   while ( myEnum8->MoveNext() )
   {
      IPEndPoint^ e = safe_cast<IPEndPoint^>(myEnum8->Current);
      Console::WriteLine( e );
   }
}
public static void ShowActiveUdpListeners()
{
    Console.WriteLine("Active UDP Listeners");
    IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
    IPEndPoint[] endPoints =  properties.GetActiveUdpListeners();
    foreach (IPEndPoint e in endPoints)
    {
        Console.WriteLine(e.ToString());
    }
}

備註

UDP 是一種無連線傳輸層通訊協定,負責傳送和接收數據報。 它定義於 IETF RFC 768 中。

UDP 接聽程式是開啟的套接字,會等候並接收UDP數據報。 由於 UDP 是無連線通訊協定,接聽程式不會維護與遠端端端點的連線。

適用於