共用方式為


IPGlobalProperties.GetUdpIPv4Statistics 方法

定義

提供本機電腦的使用者資料包通訊協定/網際網路通訊協定第 4 版 (UDP/IPv4) 統計資料。

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

傳回

UdpStatistics 物件,其提供本機電腦的 UDP/IPv4 流量統計資料。

屬性

例外狀況

呼叫 Win32 函式 GetUdpStatistics 失敗。

範例

下列範例會顯示本機計算機的 UDP/IP 統計數據。

void ShowUdpStatistics( NetworkInterfaceComponent version )
{
   IPGlobalProperties ^ properties = IPGlobalProperties::GetIPGlobalProperties();
   UdpStatistics ^ udpStat = nullptr;
   switch ( version )
   {
      case NetworkInterfaceComponent::IPv4:
         udpStat = properties->GetUdpIPv4Statistics();
         Console::WriteLine( "UDP IPv4 Statistics" );
         break;

      case NetworkInterfaceComponent::IPv6:
         udpStat = properties->GetUdpIPv6Statistics();
         Console::WriteLine( "UDP IPv6 Statistics" );
         break;

      default:
         throw gcnew ArgumentException( "version" );
         break;
   }
   Console::WriteLine( "  Datagrams Received ...................... : {0}", udpStat->DatagramsReceived );
   Console::WriteLine( "  Datagrams Sent .......................... : {0}", udpStat->DatagramsSent );
   Console::WriteLine( "  Incoming Datagrams Discarded ............ : {0}", udpStat->IncomingDatagramsDiscarded );
   Console::WriteLine( "  Incoming Datagrams With Errors .......... : {0}", udpStat->IncomingDatagramsWithErrors );
   Console::WriteLine( "  UDP Listeners ........................... : {0}", udpStat->UdpListeners );
   Console::WriteLine( "" );
}
public static void ShowUdpStatistics(NetworkInterfaceComponent version)
{
    IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
    UdpStatistics udpStat = null;

    switch (version)
    {
        case NetworkInterfaceComponent.IPv4:
            udpStat = properties.GetUdpIPv4Statistics();
            Console.WriteLine("UDP IPv4 Statistics");
            break;
        case NetworkInterfaceComponent.IPv6:
            udpStat = properties.GetUdpIPv6Statistics();
            Console.WriteLine("UDP IPv6 Statistics");
            break;
        default:
            throw new ArgumentException("version");
        //    break;
    }
    Console.WriteLine("  Datagrams Received ...................... : {0}",
        udpStat.DatagramsReceived);
    Console.WriteLine("  Datagrams Sent .......................... : {0}",
        udpStat.DatagramsSent);
    Console.WriteLine("  Incoming Datagrams Discarded ............ : {0}",
        udpStat.IncomingDatagramsDiscarded);
    Console.WriteLine("  Incoming Datagrams With Errors .......... : {0}",
        udpStat.IncomingDatagramsWithErrors);
    Console.WriteLine("  UDP Listeners ........................... : {0}",
        udpStat.UdpListeners);
    Console.WriteLine("");
}

備註

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

如需應用程式可用 UDP 流量統計資料的詳細資訊,請參閱 UdpStatistics 類別檔。 請注意,這個方法所傳回的物件會反映建立物件時所傳回的 UdpStatistics 統計數據。 這項資訊不會動態更新。

適用於