IPGlobalProperties.GetActiveUdpListeners 方法

定义

返回有关本地计算机上的 Internet 协议版本 4 (IPv4) 和 IPv6 用户数据报协议 (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 是无连接协议,因此侦听器不维护与远程终结点的连接。

适用于