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 中引入)
应用功能
ID_CAP_NETWORKING [Windows Phone]

注解

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

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

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

在绑定或连接 DatagramSocket 之前,必须设置对 DatagramSocketControl 上其他属性值所做的任何更改。 因此,如果需要更改 DontFragmentInboundBufferSizeInBytesQualityOfService 属性,则必须在成功调用 BindEndpointAsyncBindServiceNameAsyncDatagramSocket 上的 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 对象上的服务质量。

适用于

另请参阅