StreamSocketListenerControl StreamSocketListenerControl StreamSocketListenerControl StreamSocketListenerControl Class

Definition

Provides socket control data on a StreamSocketListener object.

public : sealed class StreamSocketListenerControl : IStreamSocketListenerControl, IStreamSocketListenerControl2
public sealed class StreamSocketListenerControl : IStreamSocketListenerControl, IStreamSocketListenerControl2
Public NotInheritable Class StreamSocketListenerControl Implements IStreamSocketListenerControl, IStreamSocketListenerControl2
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
ID_CAP_NETWORKING [Windows Phone]

Remarks

The StreamSocketListenerControl class provides access to advanced socket control data on a StreamSocketListener object.

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

Any changes to the StreamSocketListenerControl property values must be set before the StreamSocketListener is bound. So changes to the QualityOfService property must be set before the BindServiceNameAsync or BindEndpointAsync method is called on the StreamSocketListener.

The following example creates a StreamSocketListener, and then demonstrates how to set the QualityOfService property to LowLatency. After this is done, the app can bind and listen on the StreamSocketListener.

var listenerSocket = new Windows.Networking.Sockets.StreamSocketListener();

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

// Set QualityOfService to lowLatency
listenerSocket.Control.QualityOfService = SocketQualityOfService.lowLatency;

// Now you can call the BindServiceNameAsync or BindEndpointAsync method to listen for connections.
using Windows.Networking.Sockets;

StreamSocketListener listenerSocket = new StreamSocketListener();

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

// Set QualityOfService to lowLatency
listenerSocket.Control.QualityOfService = SocketQualityOfService.lowLatency;

// Now you can call the BindServiceNameAsync or BindEndpointAsync method to listen for connections.

using namespace Windows::Networking::Sockets;

StreamSocketListener^ listenerSocket = ref new StreamSocketListener();

// Get the current setting for this option
// This isn't required, but it shows how to get the current setting 
bool currentSetting = listenerSocket->Control->QualityOfService;

// Set QualityOfService to lowLatency
listenerSocket->Control->QualityOfService = SocketQualityOfService.lowLatency;

// Now you can call the BindServiceNameAsync or BindEndpointAsync method to listen for connections.

For more information on using StreamSocketListenerControl, see How to use advanced socket controls and How to use advanced socket controls .

Properties

KeepAlive KeepAlive KeepAlive KeepAlive

A value that indicates whether keep-alive packets should be sent on a StreamSocket object created when a connection is received by the StreamSocketListener object.

public : Platform::Boolean KeepAlive { get; set; }
public bool KeepAlive { get; set; }
Public ReadWrite Property KeepAlive As bool
var bool = streamSocketListenerControl.keepAlive;
streamSocketListenerControl.keepAlive = bool;
Value
Platform::Boolean bool bool bool

Whether keep-alive packets are sent on the StreamSocket object created.

Remarks

When this property is true, the StreamSocket object created sends keep-alive packets when no data or acknowledgment packets have been received for the TCP connection within an interval. When a StreamSocket is created, the default value for this property is false.

This property may be set before the StreamSocketListener starts listening for incoming connections. After the StreamSocketListener starts listening for incoming connections, setting the property will result in an error.

For more detailed information, see the SO_KEEPALIVE socket option in the Windows Sockets documentation.

See Also

NoDelay NoDelay NoDelay NoDelay

A value that indicates whether the Nagle algorithm is used on a StreamSocket object created when a connection is received by the StreamSocketListener object.

public : Platform::Boolean NoDelay { get; set; }
public bool NoDelay { get; set; }
Public ReadWrite Property NoDelay As bool
var bool = streamSocketListenerControl.noDelay;
streamSocketListenerControl.noDelay = bool;
Value
Platform::Boolean bool bool bool

A value that indicates whether the Nagle algorithm is used on the TCP connection of a StreamSocket object created.

Remarks

The NoDelay property controls whether Nagle's algorithm is enabled or disabled on a StreamSocket object created. The default value for the NoDelay property on a StreamSocket is true.

Nagle's algorithm is a technique to improving the efficiency of TCP/IP networks by reducing the number of packets that are needed to be sent over the network. The algorithm tries to deal with problems caused by an application that repeatedly emits data in small chunks. A TCP packet has a 40-byte header (20 bytes for IP and 20 bytes for TCP). So if an app sends only 4 bytes in a packet, the overhead on the packet data is very large. This can occur for a remote access protocol (telnet or secure shell, for example) where most key presses may generate only a single byte or two of data that is transmitted immediately. Over a slow link, many of these packets may be in transit over the network at the same time. Nagle's algorithm works by combining a number of small outgoing messages, and sending them all at once. When there is a sent packet for which the sender has received no acknowledgment, the sender keeps buffering output until it has a full packet's worth of output. This allows the output to be sent all at once. The impact of applying Nagle's algorithm is to increase the bandwidth at the expense of latency. A well-written app that buffers sends internally should not need to use Nagle's algorithm.

When this property is true, the StreamSocket will disable Nagle's algorithm on the TCP connection. This setting reduces the potential delays when sending small messages. When a StreamSocket is created, the default value for this property is true.

When this property is false, the StreamSocket will enable Nagle's algorithm on the TCP connection. This setting can increase the bandwidth at the expense of latency, but should only be used with caution. There are some adverse side effects possible when Nagle's algorithm is enabled and certain other TCP optimizations are also used.

This property may be set before the StreamSocketListener starts listening for incoming connections. After the StreamSocketListener starts listening for incoming connections, setting the property will result in an error.

This property sets the value of the TCP_NODELAY socket option on the TCP socket used by the StreamSocket.

See Also

OutboundBufferSizeInBytes OutboundBufferSizeInBytes OutboundBufferSizeInBytes OutboundBufferSizeInBytes

The size, in bytes, of the send buffer to be used for sending data on a StreamSocket object created when a connection is received by the StreamSocketListener object.

public : unsigned int OutboundBufferSizeInBytes { get; set; }
public uint OutboundBufferSizeInBytes { get; set; }
Public ReadWrite Property OutboundBufferSizeInBytes As uint
var uint = streamSocketListenerControl.outboundBufferSizeInBytes;
streamSocketListenerControl.outboundBufferSizeInBytes = uint;
Value
unsigned int uint uint uint

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

Remarks

The OutboundBufferSizeInBytes property sets the value of the SO_SNDBUF socket option on the TCP socket used by the StreamSocket created. The default value is the local computer's default send buffer size. This value varies based on the system memory size. For more detailed information, see SOL_SOCKET Socket Options in the Windows Sockets documentation.

For most apps, this property should not be set since this disables TCP send auto-tuning by the system on this StreamSocket object. With TCP send auto-tuning disabled, network throughput is often worse especially on a connections with high latency. So this property should only be used in very specific situations.

This property may be set before the StreamSocketListener starts listening for incoming connections. After the StreamSocketListener starts listening for incoming connections, setting the property will result in an error.

See Also

OutboundUnicastHopLimit OutboundUnicastHopLimit OutboundUnicastHopLimit OutboundUnicastHopLimit

The hop limit on an outbound packet sent to a unicast IP address by the StreamSocket object created when a connection is received by the StreamSocketListener object.

public : byte OutboundUnicastHopLimit { get; set; }
public byte OutboundUnicastHopLimit { get; set; }
Public ReadWrite Property OutboundUnicastHopLimit As byte
var byte = streamSocketListenerControl.outboundUnicastHopLimit;
streamSocketListenerControl.outboundUnicastHopLimit = byte;
Value
byte byte byte byte

The hop limit on an outbound packet sent by the StreamSocket object created. The default is 128.

Remarks

This value indicates the hop limit that is set on an outbound TCP packet sent to a unicast IP address using the StreamSocket object created. This property is used to set the Time to Live (TTL) field in an IPv4 packet header. This property is used to set the Hop Limit field in an IPv6 header. The default value for this property is 128.

This property may be set before the StreamSocketListener starts listening for incoming connections. After the StreamSocketListener starts listening for incoming connections, setting the property will result in an error.

Setting this property may throw an exception if the system doesn't support setting the TTL.

See Also

QualityOfService QualityOfService QualityOfService QualityOfService

The quality of service to be set on a StreamSocket object created when a connection is received by the StreamSocketListener object.

public : SocketQualityOfService QualityOfService { get; set; }
public SocketQualityOfService QualityOfService { get; set; }
Public ReadWrite Property QualityOfService As SocketQualityOfService
var socketQualityOfService = streamSocketListenerControl.qualityOfService;
streamSocketListenerControl.qualityOfService = socketQualityOfService;
Value
SocketQualityOfService SocketQualityOfService SocketQualityOfService SocketQualityOfService

The quality of service set on a StreamSocket object created when a connection is received by the StreamSocketListener object.

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
ID_CAP_NETWORKING [Windows Phone]
See Also

See Also