Jaa


MessageWebSocketControl Class

Definition

Provides socket control data on a MessageWebSocket.

public ref class MessageWebSocketControl sealed
public ref class MessageWebSocketControl sealed : IWebSocketControl2
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class MessageWebSocketControl final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class MessageWebSocketControl final : IWebSocketControl2
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class MessageWebSocketControl
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class MessageWebSocketControl : IWebSocketControl2
Public NotInheritable Class MessageWebSocketControl
Public NotInheritable Class MessageWebSocketControl
Implements IWebSocketControl2
Inheritance
Object Platform::Object IInspectable MessageWebSocketControl
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

The MessageWebSocketControl class provides access to advanced socket control data on a MessageWebSocket object.

A MessageWebSocketControl object is automatically created with the parent MessageWebSocket object. The MessageWebSocket.Control property provides access to the associated MessageWebSocket object.

The SupportedProtocols property gets the value of this property and can be called at any time.

The MessageType property can be changed at any time before or after the MessageWebSocket is connected. This allows an app to switch between binary and UTF-8 messages when needed.

The OutboundBufferSizeInBytes property must be set before the MessageWebSocket is connected. Setting this property after the MessageWebSocket is connected has no effect.

Any changes to the other property values on the MessageWebSocketControl must be set before the DatagramSocket is bound or connected. As a result if you need to make changes to the MaxMessageSize, ProxyCredential, OutboundBufferSizeInBytes, or ServerCredential properties, then these changes must occur before a successful call to the ConnectAsync method on the MessageWebSocket.

The following example creates a MessageWebSocket, and then demonstrates how to set the MessageWebSocketControl.MessageType property to binary. (Other properties may be set in a similar manner.) After this is done, the app can connect the MessageWebSocket.

using Windows.Networking.Sockets;

MessageWebSocket clientWebSocket = new MessageWebSocket();

// Get the current setting for this option.
// This isn't required, but it shows how to get the current setting.
SocketMessageType currentSetting = clientWebSocket.Control.MessageType;

// Set messageType to Binary.
clientWebSocket.Control.MessageType = SocketMessageType.Binary;

// Now you can call the ConnectAsync method to connect the MessageWebSocket.
#include <winrt/Windows.Networking.Sockets.h>
using namespace winrt;
...
Windows::Networking::Sockets::MessageWebSocket 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().MessageType() };

// Set QualityOfService to Binary.
clientSocket.Control().MessageType(Windows::Networking::Sockets::SocketMessageType::Binary);

// Now you can call the ConnectAsync function to connect the MessageWebSocket.
using namespace Windows::Networking::Sockets;

MessageWebSocket^ clientWebSocket = ref new MessageWebSocket();

// Get the current setting for this option.
// This isn't required, but it shows how to get the current setting.
SocketMessageType currentSetting = clientWebSocket->Control->MessageType;

// Set messageType to Binary.
clientWebSocket->Control->MessageType = SocketMessageType::Binary;

// Now you can call the ConnectAsync method to connect the MessageWebSocket.

For more information on using MessageWebSocketControl, see How to use advanced WebSocket controls.

Version history

Windows version SDK version Value added
1607 14393 IgnorableServerCertificateErrors
1709 16299 ActualUnsolicitedPongInterval
1709 16299 ClientCertificate
1709 16299 DesiredUnsolicitedPongInterval
1709 16299 ReceiveMode

Properties

ActualUnsolicitedPongInterval

Allows an app to get the actual unsolicited WebSocket PONG interval.

ClientCertificate

Gets the certificate provided by the client when a secure WebSocket connection has been established.

DesiredUnsolicitedPongInterval

Allows an app to get and set the desired unsolicited WebSocket PONG interval.

IgnorableServerCertificateErrors

Gets a list of ignorable server certificate errors. Get this list and add ChainValidationResult values for server certificate errors that you wish to ignore during the secure WebSocket (wss:// protocol) server certificate validation process.

MaxMessageSize

The maximum message size, in bytes, for a WebSocket message to be configured on the MessageWebSocket object.

MessageType

The WebSocket message type to be configured on a MessageWebSocket object for write operations.

OutboundBufferSizeInBytes

The size, in bytes, of the send buffer to be used for sending data on a MessageWebSocket object.

ProxyCredential

The credential to use to authenticate to the proxy server through HTTP header authentication using a MessageWebSocket object.

ReceiveMode

Allows clients to control receiving either complete or partial messages.

ServerCredential

The credential to use to authenticate to the WebSocket server through HTTP header authentication using a MessageWebSocket object.

SupportedProtocols

Gets a collection that can be used to add a list of supported sub-protocols that will be advertised to the server during the connect handshake.

Applies to

See also