语言

DatagramSocketControl 类

定义

在 DatagramSocket 对象上提供套接字控制数据。

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
继承
Object Platform::Object IInspectable DatagramSocketControl
属性

Windows 要求

要求 说明
设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

注解

DatagramSocketControl 类提供对 DatagramSocket 对象上的高级套接字控制数据的访问。

DatagramSocketControl 对象是使用父 DatagramSocket 对象自动创建的。 DatagramSocket.Control 属性提供对关联的 DatagramSocketControl 对象的访问。

可以在 DatagramSocket 绑定或连接之前或之后设置 OutboundUnicastHopLimit 属性。 在绑定或连接的 DatagramSocket 上更改此值之前,应首先刷新任何传出数据包,以确保使用以前的跃点限制发送所有以前写入的数据。

在 DatagramSocket 绑定或连接之前,必须设置对 DatagramSocketControl 上其他属性值所做的任何更改。 因此,如果需要更改 DontFragment、InboundBufferSizeInBytes 或 QualityOfService 属性,则必须在成功调用 BindEndpointAsync、BindServiceNameAsync 或 DatagramSocket 上的 ConnectAsync 方法之前进行这些更改。

以下示例创建 DatagramSocket,然后演示如何将 QualityOfService 属性设置为 LowLatency。 其他属性可以采用类似的方式进行设置。 完成此操作后,应用可以连接 DatagramSocket 或在套接字上发送数据。

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 的详细信息,请参阅 如何使用高级套接字控件。

属性

名称 说明
DontFragment

获取或设置一个布尔值,该值指定 DatagramSocket 是否允许将 UDP 的 IP 数据报分段。

InboundBufferSizeInBytes

获取或设置用于接收 DatagramSocket 对象上的数据的缓冲区的大小(以字节为单位)。

MulticastOnly

获取或设置一个布尔值,该值指定 DatagramSocket 是否能够与其他 Win32 或 WinRT 多播套接字共存到同一地址/端口。

OutboundUnicastHopLimit

获取或设置 DatagramSocket 对象发送到单播 IP 地址的出站数据包的跃点限制。

QualityOfService

获取或设置 DatagramSocket 对象的服务质量。

适用于

另请参阅