DatagramSocketControl 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 DatagramSocket 物件上的 socket 控制資料。
public ref class DatagramSocketControl sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class DatagramSocketControl final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class DatagramSocketControl
Public NotInheritable Class DatagramSocketControl
- 繼承
- 屬性
Windows 需求
| 規格需求 | Description |
|---|---|
| 裝置系列 |
Windows 10 (已於 10.0.10240.0 引進)
|
| API contract |
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
|
備註
DatagramSocketControl 類別提供存取 DatagramSocket 物件上的進階套接字控制資料。
DatagramSocketControl 物件會自動建立,使用父 DatagramSocket 物件。 DatagramSocket.Control 屬性提供對應的 DatagramSocketControl 物件存取。
OutboundUnicastHopLimit 屬性可以在 DatagramSocket 綁定或連接之前或之後設定。 在更改綁定或連接資料 報套接字的此值前,應先清除任何發出封包,以確保所有先前寫入的資料都以先前的跳數限制發送。
DatagramSocketControl 上其他屬性值的任何變更都必須在綁定或連接 DatagramSocket 之前設定。 因此,如果你需要對 DontFragment、InboundBufferSizeInBytes 或 QualityOfService 屬性做變更,這些變更必須在成功呼叫 BindEndpointAsync、BindServiceNameAsync 或 DatagramSocket 上的 ConnectAsync 方法之前完成。
以下範例建立 DatagramSocket,並示範如何將 QualityOfService 屬性設定為 低延遲。 其他屬性也可能以類似方式設定。 完成後,應用程式可以連接 DatagramSocket 或在該 socket 上傳送資料。
using Windows.Networking.Sockets;
DatagramSocket clientSocket = new DatagramSocket();
// Get the current setting for this option.
// This isn't required, but it shows how to get the current setting.
var currentSetting = clientSocket.Control.QualityOfService;
// Set QualityOfService to LowLatency.
clientSocket.Control.QualityOfService = SocketQualityOfService.LowLatency;
// Now you can call the ConnectAsync method to connect the DatagramSocket.
#include <winrt/Windows.Networking.Sockets.h>
using namespace winrt;
...
Windows::Networking::Sockets::DatagramSocket clientSocket;
// Get the current setting for this option.
// This isn't required, but it shows how to get the current setting.
auto currentSetting{ clientSocket.Control().QualityOfService() };
// Set QualityOfService to LowLatency.
clientSocket.Control().QualityOfService(Windows::Networking::Sockets::SocketQualityOfService::LowLatency);
// Now you can call the ConnectAsync function to connect the DatagramSocket.
using namespace Windows::Networking::Sockets;
DatagramSocket^ clientSocket = ref new DatagramSocket();
// Get the current setting for this option.
// This isn't required, but it shows how to get the current setting.
auto currentSetting = clientSocket->Control->QualityOfService;
// Set QualityOfService to LowLatency.
clientSocket->Control->QualityOfService = SocketQualityOfService::LowLatency;
// Now you can call the ConnectAsync method to connect the DatagramSocket.
欲了解更多使用 DatagramSocketControl 的資訊,請參閱 《如何使用進階套接字控制法》。
屬性
| 名稱 | Description |
|---|---|
| DontFragment |
取得或設定一個布林值,指定 DatagramSocket 是否允許 UDP 的 IP 資料報被分割。 |
| InboundBufferSizeInBytes | |
| MulticastOnly |
取得或設定一個布林值,指定 DatagramSocket 是否能與其他綁定在同一位址/埠的 Win32 或 WinRT 多播套接字共存。 |
| OutboundUnicastHopLimit |
接收或設定由 DatagramSocket 物件發送到單播 IP 位址的出站封包的跳躍限制。 |
| QualityOfService |
取得或設定 DatagramSocket 物件的服務品質。 |