/windows.networking.sockets/datagramsocketcontrol.md

https://github.com/MicrosoftDocs/winrt-api · Markdown · 83 lines · 54 code · 29 blank · 0 comment · 0 complexity · 069492d36c00c52c14ab60f7a04d88bc MD5 · raw file

  1. ---
  2. -api-id: T:Windows.Networking.Sockets.DatagramSocketControl
  3. -api-type: winrt class
  4. ---
  5. <!-- Class syntax.
  6. public class DatagramSocketControl : Windows.Networking.Sockets.IDatagramSocketControl, Windows.Networking.Sockets.IDatagramSocketControl2, Windows.Networking.Sockets.IDatagramSocketControl3
  7. -->
  8. # Windows.Networking.Sockets.DatagramSocketControl
  9. ## -description
  10. Provides socket control data on a [DatagramSocket](datagramsocket.md) object.
  11. ## -remarks
  12. The DatagramSocketControl class provides access to advanced socket control data on a [DatagramSocket](datagramsocket.md) object.
  13. A DatagramSocketControl object is automatically created with the parent [DatagramSocket](datagramsocket.md) object. The [DatagramSocket.Control](datagramsocket_control.md) property provides access to the associated DatagramSocketControl object.
  14. The [OutboundUnicastHopLimit](datagramsocketcontrol_outboundunicasthoplimit.md) property can be set before or after the [DatagramSocket](datagramsocket.md) is bound or connected. Before changing this value on a bound or connected [DatagramSocket](datagramsocket.md), any outgoing packets should first be flushed to ensure that all previously-written data is sent out with the previous hop limit.
  15. Any changes to the other property values on the DatagramSocketControl must be set before the [DatagramSocket](datagramsocket.md) is bound or connected. As a result if you need to make changes to the [DontFragment](datagramsocketcontrol_dontfragment.md), [InboundBufferSizeInBytes](datagramsocketcontrol_inboundbuffersizeinbytes.md), or [QualityOfService](datagramsocketcontrol_qualityofservice.md) properties, then these changes must occur before a successful call to the [BindEndpointAsync](datagramsocket_bindendpointasync_1396029045.md), [BindServiceNameAsync](datagramsocket_bindservicenameasync_440542334.md), or one of the [ConnectAsync](datagramsocket_connectasync_13692504.md) methods on the [DatagramSocket](datagramsocket.md).
  16. The following example creates a [DatagramSocket](datagramsocket.md), and then demonstrates how to set the [QualityOfService](datagramsocketcontrol_qualityofservice.md) property to **LowLatency**. Other properties may be set in a similar manner. After this is done, the app can connect the [DatagramSocket](datagramsocket.md) or send data on the socket.
  17. ```csharp
  18. using Windows.Networking.Sockets;
  19. DatagramSocket clientSocket = new DatagramSocket();
  20. // Get the current setting for this option.
  21. // This isn't required, but it shows how to get the current setting.
  22. var currentSetting = clientSocket.Control.QualityOfService;
  23. // Set QualityOfService to LowLatency.
  24. clientSocket.Control.QualityOfService = SocketQualityOfService.LowLatency;
  25. // Now you can call the ConnectAsync method to connect the DatagramSocket.
  26. ```
  27. ```cppwinrt
  28. #include <winrt/Windows.Networking.Sockets.h>
  29. using namespace winrt;
  30. ...
  31. Windows::Networking::Sockets::DatagramSocket clientSocket;
  32. // Get the current setting for this option.
  33. // This isn't required, but it shows how to get the current setting.
  34. auto currentSetting{ clientSocket.Control().QualityOfService() };
  35. // Set QualityOfService to LowLatency.
  36. clientSocket.Control().QualityOfService(Windows::Networking::Sockets::SocketQualityOfService::LowLatency);
  37. // Now you can call the ConnectAsync function to connect the DatagramSocket.
  38. ```
  39. ```cppcx
  40. using namespace Windows::Networking::Sockets;
  41. DatagramSocket^ clientSocket = ref new DatagramSocket();
  42. // Get the current setting for this option.
  43. // This isn't required, but it shows how to get the current setting.
  44. auto currentSetting = clientSocket->Control->QualityOfService;
  45. // Set QualityOfService to LowLatency.
  46. clientSocket->Control->QualityOfService = SocketQualityOfService::LowLatency;
  47. // Now you can call the ConnectAsync method to connect the DatagramSocket.
  48. ```
  49. For more information on using DatagramSocketControl, see [How to use advanced socket controls](/previous-versions/windows/apps/jj150598(v=win.10)).
  50. ## -examples
  51. ## -see-also
  52. [How to use advanced socket controls](/previous-versions/windows/apps/jj150598(v=win.10)), [DatagramSocket](datagramsocket.md), [DatagramSocket.Control](datagramsocket_control.md), [DatagramSocketInformation](datagramsocketinformation.md), [DatagramSocket sample](https://github.com/microsoftarchive/msdn-code-gallery-microsoft/tree/master/Official%20Windows%20Platform%20Sample/DatagramSocket%20sample), [DatagramSocket sample](https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DatagramSocket)
  53. ## -capabilities
  54. ID_CAP_NETWORKING [Windows Phone]