PingOptions.Ttl 屬性

定義

取得或設定路由節點數目,這些節點可在丟棄 Ping 資料前轉送該資料。

public:
 property int Ttl { int get(); void set(int value); };
public int Ttl { get; set; }
member this.Ttl : int with get, set
Public Property Ttl As Integer

屬性值

Int32 值,指定可以轉送 Ping 資料封包的次數。 預設值為 128。

例外狀況

為設定作業指定的值小於或等於零。

範例

下列程式代碼範例示範如何使用建 PingOptions 構函式設定此屬性的值,然後顯示值。

// Set options for transmission:
// The data can go through 64 gateways or routers
// before it is destroyed, and the data packet
// cannot be fragmented.
PingOptions ^ options = gcnew PingOptions( 64,true );
Console::WriteLine( "Time to live: {0}", options->Ttl );
Console::WriteLine( "Don't fragment: {0}", options->DontFragment );
// Set options for transmission:
// The data can go through 64 gateways or routers
// before it is destroyed, and the data packet
// cannot be fragmented.
PingOptions options = new PingOptions (64, true);

Console.WriteLine ("Time to live: {0}", options.Ttl);
Console.WriteLine ("Don't fragment: {0}", options.DontFragment);

備註

當閘道和路由器透過網路傳輸封包時,它們會遞減目前在封包標頭中找到的存留時間 (TTL) 值。 如果 TTL 值達到零,封包會被視為無法傳遞,而且會被捨棄。 如果您想要測試用來傳輸數據的路由器和閘道數目,此選項會很有用。

適用於