StreamSocket StreamSocket StreamSocket StreamSocket Class

Supports network communication using a stream socket over TCP or Bluetooth RFCOMM in Windows Store app.

Syntax

Declaration

public sealed class StreamSocketpublic sealed class StreamSocketPublic NotInheritable Class StreamSocket

Remarks

The StreamSocket class supports network communications that use a stream socket over TCP or Bluetooth RFCOMM in Windows Store app.

For a client app, the most common sequence of operations using a StreamSocket are the following:

Explicitly closing a StreamSocket object (calling the Close() method) will ensure a graceful disconnect if no pending read or write operations exist on the socket. All pending reads are automatically aborted and the StreamSocket waits for any ongoing I/O to complete before tearing down the connection. If no unread data remains on the socket after the ongoing I/O is finished, a graceful disconnect (FIN) is guaranteed to occur. Otherwise, an ungraceful disconnect (RST) occurs.

When an active (still connected) StreamSocket object goes out of scope, an abortive (non-graceful) disconnect may result, which can lead to previously-sent data being discarded before it is read by the remote peer. It is strongly recommended that Close() (the Close() method in JavaScript, the method in C# and VB.NET, or the delete operator in C++) be called on a StreamSocket object before it goes out of scope.

Whenever a read or write operation is cancelled, the I/O operation completes with Error state and the associated StreamSocket object immediately tears down the connection, which leads to an ungraceful disconnect (RST) if any unread or unsent data remains on the socket.

Ungraceful disconnects (RST) will always occur if: An abnormal termination occurs (e.g., the app crashes); or an abnormal connection failure is detected by the networking stack (e.g., TCP retransmit timeout).

The StreamSocket object is also used in conjunction with the StreamSocketListener object to listen for incoming connections over TCP or Bluetooth RFCOMM in server apps or peer-to-peer apps. A StreamSocket object is returned by the Socket property on the ConnectionReceived event when a StreamSocketListener object receives a TCP or Bluetooth RFCOMM connection request. For more information, see StreamSocketListener.

Support for proxies

In a Windows Store app, the StreamSocket class supports connecting to a remote endpoint when proxies are required to complete the connection. This support for proxies is automatic and transparent to the app. A StreamSocket can establish a connection through authenticating proxies as well as through other proxies where authentication is not needed. Authenticating proxies only work if Internet Explorer or an app that uses the HttpClient class in the Windows.Web.Http namespace has previously successfully authenticated with the proxy and the credentials previously used for the authentication are still valid. The support for authenticating proxies does not work if a web browser other than Internet Explorer was used to provide the authentication credentials to the proxy. Connecting through proxies is not supported if a local host address or a specific network adapter is specified on the ConnectAsync(Windows.Networking.EndpointPair) method.

In a Windows Store app, the ConnectAsync(Windows.Networking.EndpointPair) methods on the StreamSocket object try to discover proxies and the current proxy configuration both before and after name resolution to help speed up connection establishment. If a port is specified for the endpoint rather than a service name, both proxy discovery and name resolution are initiated internally. If proxy discovery completes before name resolution and the CanConnectDirectly property on the ProxyConfiguration object is false, then a proxy connection will be attempted. Once name resolution completes, proxy discovery is initiated again with the resolved endpoint address to determine the current proxy configuration. If CanConnectDirectly indicates after name resolution that the app can connect directly to the remote endpoint, then a socket connection will be attempted directly to the endpoint. If CanConnectDirectly is false after name resolution, then a socket connection will be attempted directly to the endpoint and a parallel socket connection is attempted through the proxy. The first connection to succeed is used by the StreamSocket and the other connection is canceled.

There may be cases where CanConnectDirectly returns false, yet it does not mean you cannot access the resource directly. A local network could be configured to have support for both a proxy and network address translation (NAT). The WPAD script used to supply proxy information to a web browser or HttpClient tells Windows that it should use the proxy. This can cause problems when the remote endpoint is not expecting a proxy connection (an HTTP CONNECT request, for example). An app can use the GetProxyConfigurationAsync(Windows.Foundation.Uri) method on the NetworkInformation object passing the remote endpoint and port for the uri parameter to retrieve proxy information to help determine when this condition is suspected. A way to avoid proxy connection requests from being sent when a server can only handle direct connections is to use the ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter) method, since the proxy-related logic is disabled when a specific network adapter is selected.

In a Windows Phone Store app, the StreamSocket does not provide automatic support for proxies since the ProxyConfiguration class is not supported on Windows Phone.

Handling exceptions

You must write code to handle exceptions when you call asynchronous methods on the StreamSocket class. Exceptions can result from parameter validation errors, name resolutions failures, and network errors. Exceptions from network errors (loss of connectivity, connection failures, and server failures, for example) can happen at any time. These errors result in exceptions being thrown. If not handled by your app, an exception can cause your entire app to be terminated by the runtime.

The Windows.Networking.Sockets namespace has features that simplify handling errors when using sockets. The GetStatus(System.Int32) method on the SocketError class can convert the HRESULT from an exception to a SocketErrorStatus enumeration value. This can be useful for handling specific network exceptions differently in your app. An app can also use the HRESULT from the exception on parameter validation errors to learn more detailed information on the error that caused the exception.

For more information on possible exceptions and how to handle exceptions, see Handling exceptions in network apps.

Using StreamSocket with Proximity, Wi-Fi Direct, and Bluetooth

Your app can use a StreamSocket for network connections between devices that are within close range. Classes in the Windows.Networking.Proximity namespace support network connections with a StreamSocket to nearby devices that use Bluetooth or Wi-Fi Direct. The PeerFinder and related classes in the Windows.Networking.Proximity namespace let your app discover another instance of your app on a nearby device. The FindAllPeersAsync() method browses for peer computers that are running the same app within wireless range. The ConnectAsync(Windows.Networking.Proximity.PeerInformation) method returns a connected StreamSocket that your app can use to transfer network data with the nearby peer app. For more information, see Supporting proximity and tapping, Windows.Networking.Proximity, PeerFinder, and the Proximity sample.

Your app can also use a StreamSocket for network connections between devices that use Wi-Fi Direct with classes in the Windows.Devices.WiFiDirect namespace. The WiFiDirectDevice class can be used to locate other devices that have a Wi-Fi Direct (WFD) capable device. The GetDeviceSelector(Windows.Devices.WiFiDirect.WiFiDirectDeviceSelectorType) method gets the device identifier for a nearby WFD device. Once you have a reference to a nearby WFD device, you can call the GetConnectionEndpointPairs() method to get an EndpointPair object. The ConnectAsync(Windows.Networking.EndpointPair) or ConnectAsync(Windows.Networking.EndpointPair,Windows.Networking.Sockets.SocketProtectionLevel) method on the StreamSocket class can then be used to establish a socket connection. For more information, see Windows.Devices.WiFiDirect and WiFiDirectDevice.

Bluetooth uses Bluetooth Service IDs as endpoints for StreamSocket connections, not hostnames or IP addresses. To use a StreamSocket with Bluetooth, the bluetooth.rfcomm device capability must be set in the app manifest. For more information, see the Windows.Devices.Bluetooth.Rfcomm namespace, How to specify device capabilities for Bluetooth, and the Bluetooth Rfcomm Chat sample.

Using StreamSocket on Windows Server 2012

On Windows Server 2012 and Windows Server 2012 R2, the Windows.Networking.dll that implements most of the classes in the Windows.Networking.Sockets namespace will fail to load unless the Media Foundation feature is enabled. As a result, apps that use StreamSocket and related socket classes in the Windows.Networking.Sockets namespace will fail if the Media Foundation feature is disabled. Windows Server 2012 or Windows Server 2012 R2 installs with the Media Foundation feature disabled.

The Media Foundation feature can be enabled on Windows Server 2012 or Windows Server 2012 R2 using Server Manager or by entering the following text in a command prompt or a script:

dism /online /enable-feature /featurename:ServerMediaFoundationAfter the Media Foundation feature is enabled, the user is prompted to restart. Once the computer is restarted, classes for sockets and WebSockets in the Windows.Networking.Sockets namespace will work as expected.

Constructors summary

Creates a new StreamSocket object.

Properties summary

Gets socket control data on a StreamSocket object.

Gets socket information on a StreamSocket object.

Gets the input stream to read from the remote destination on a StreamSocket object.

Gets the output stream to write to the remote host on a StreamSocket object.

Methods summary

Cancels pending reads and writes over a StreamSocket object.

Closes the StreamSocket object.

Starts an asynchronous operation on a StreamSocket object to connect to a remote network destination specified as an EndpointPair object.

Starts an asynchronous operation on a StreamSocket object to connect to a remote network destination specified as an EndpointPair object and a SocketProtectionLevel enumeration. This method is not callable from JavaScript.

Starts an asynchronous operation on a StreamSocket object to connect to a remote network destination specified by a remote hostname and a remote service name.

Starts an asynchronous operation on a StreamSocket object to connect to a remote destination specified by a remote hostname, a remote service name, and a SocketProtectionLevel.

Starts an asynchronous operation on a StreamSocket object on a specified local network adapter to connect to a remote destination specified by a remote hostname, a remote service name, and a SocketProtectionLevel.

Enables your app's background task to be triggered by the socket broker when traffic for this StreamSocket arrives while the app is not active.

Enables or disables the ability of your app's background task to be triggered by the socket broker when traffic for this StreamSocket arrives while the system is in connected standby.

Gets a list of EndpointPair objects based on a remote hostname and remote service name that can be used to send TCP packets to a remote network destination.

Gets a list of EndpointPair objects based on a remote hostname and remote service name and the sort order to be used.

Transfers ownership of the StreamSocket to the socket brokering service, which monitors socket activity and notifies the app through a background task if there is any activity.

Transfers ownership of the StreamSocket to the socket brokering service, which monitors socket activity and notifies the app through a background task if there is any activity. Specifies a new SocketActivityContext for the socket.

Transfers ownership of the StreamSocket to the socket brokering service, which monitors socket activity and notifies the app through a background task if there is any activity. Specifies a new SocketActivityContext and a keep alive time for the socket.

Starts an asynchronous operation to upgrade a connected socket to use SSL on a StreamSocket object.

Constructors

  • StreamSocket()
    StreamSocket()
    StreamSocket()
    StreamSocket()

    Creates a new StreamSocket object.

    public StreamSocket()public StreamSocket()Public Function StreamSocket() As

Properties

Methods

  • CancelIOAsync()
    CancelIOAsync()
    CancelIOAsync()
    CancelIOAsync()

    Cancels pending reads and writes over a StreamSocket object.

    public IAsyncAction CancelIOAsync()public IAsyncAction CancelIOAsync()Public Function CancelIOAsync() As IAsyncAction

    Returns

    Remarks

    Call CancelIOAsync() to cancel any pending reads or writes on this socket before you call TransferOwnership(System.String) when your app is about to be suspended.

    CancelIOAsync() does not guarantee that all read/write completion handlers have finished executing before it signals completion. It does, however, guarantee that all I/O operations will have reached a terminal state (either Completed or Error) by the time it signals completion. If your app needs to wait for all pending I/O operation handlers to finish executing, you must implement your own app-level sychronization logic. The Socket Activity Stream Socket sample demonstrates one way to do this.

    Note

    CancelIOAsync() cancels pending writes and reads in the Windows Runtime, but if there is a write buffer pending in networking drivers, it flushes the write.

  • Close()
    Close()
    Close()
    Close()

    Closes the StreamSocket object.

    public void Close()public void Close()Public Function Close() As void

    Remarks

    The Close() method aborts any pending operations and releases all unmanaged resources associated with the StreamSocket object. Aborting pending read operations on an InputStream or aborting pending write operations on an OutputStream will also result in the StreamSocket object being closed.

    The Close() is used by Windows Store app s written in JavaScript. For apps written using the .NET Framework 4.5 in C# and VB.NET, the Close() method is exposed as the method on the StreamSocket. For apps written in C++, the Close() method will be called when using the delete keyword on the object.

  • ConnectAsync(Windows.Networking.EndpointPair)
    ConnectAsync(Windows.Networking.EndpointPair)
    ConnectAsync(Windows.Networking.EndpointPair)
    ConnectAsync(Windows.Networking.EndpointPair)

    Starts an asynchronous operation on a StreamSocket object to connect to a remote network destination specified as an EndpointPair object.

    public IAsyncAction ConnectAsync(Windows.Networking.EndpointPair)public IAsyncAction ConnectAsync(Windows.Networking.EndpointPair)Public Function ConnectAsync(Windows.Networking.EndpointPair) As IAsyncAction

    Parameters

    Returns

    Remarks

    If the EndpointPair object passed in the endpointPair parameter contains null for the LocalHostName property, then the system will supply the local IP address that will be used. If the EndpointPair object passed in the endpointPair parameter contains an empty string for the LocalServiceName property, then the system will supply the local TCP port that will be used.

    In a Windows Store app, the StreamSocket class supports connecting to a remote endpoint when proxies are required to complete the connection. This support for proxies is automatic and transparent to the app. Connecting through proxies is not supported when a local host address is specified, so the LocalHostName property passed in the endpointPair parameter must be null. For more detailed information, see the remarks on Support for proxies in the StreamSocket class reference.

    In a Windows Phone Store app, the StreamSocket class does not provide automatic support for proxies.

  • ConnectAsync(Windows.Networking.EndpointPair,Windows.Networking.Sockets.SocketProtectionLevel)
    ConnectAsync(Windows.Networking.EndpointPair,Windows.Networking.Sockets.SocketProtectionLevel)
    ConnectAsync(Windows.Networking.EndpointPair,Windows.Networking.Sockets.SocketProtectionLevel)
    ConnectAsync(Windows.Networking.EndpointPair,Windows.Networking.Sockets.SocketProtectionLevel)

    Starts an asynchronous operation on a StreamSocket object to connect to a remote network destination specified as an EndpointPair object and a SocketProtectionLevel enumeration. This method is not callable from JavaScript.

    public IAsyncAction ConnectAsync(Windows.Networking.EndpointPair,Windows.Networking.Sockets.SocketProtectionLevel)public IAsyncAction ConnectAsync(Windows.Networking.EndpointPair,Windows.Networking.Sockets.SocketProtectionLevel)Public Function ConnectAsync(Windows.Networking.EndpointPair,Windows.Networking.Sockets.SocketProtectionLevel) As IAsyncAction

    Parameters

    Returns

    Remarks

    If the EndpointPair object passed in the endpointPair parameter contains null for the LocalHostName property, then the system will supply the local IP address that will be used. If the EndpointPair object passed in the endpointPair parameter contains an empty string for the LocalServiceName property, then the system will supply the local TCP port that will be used.

    If the EndpointPair object passed in the endpointPair parameter contains null for the LocalServiceName property, then an error will occur.

    The ConnectAsync(Windows.Networking.EndpointPair,Windows.Networking.Sockets.SocketProtectionLevel) method is not exposed in JavaScript. This method can't be called from JavaScript since it has the same number of arguments as the ConnectAsync(Windows.Networking.HostName,System.String) method.

    Apps written in JavaScript can't connect a StreamSocket using an EndpointPair using SSL directly. In order to connect an EndpointPair using SSL, JavaScript apps can use the following code instead.

    
    var clientSocket = new Windows.Networking.Sockets.StreamSocket();
    var remoteName = new Windows.Networking.HostName("www.contoso.com");
    var myEndpointPair = EndpointPair();
    
    // Set properties needed on the EndpointPair
    // We only set remote properties and the localServiceName,
    // But the localHostName could also be set
    
    myEndpointPair.localServiceName = "12345";
    myEndpointPair.remoteHostName = remoteName;
    myEndpointPair.remoteServiceName = "http";
    
    // First connect the socket without SSL
    clientSocket.connectAsync(myEendpointPair>).then(function () {
        // Now upgrade the connection to SSL
        clientSocket.upgradeToSslAsync(SocketProtectionLevel.Ssl).then(function () {
            // now connected using SSL
        }
    }
    

    When the protectionLevel parameter is set to a value that requires SSL or TLS, the socket connect operation may not timeout if the remote endpoint does not support SSL or TLS. This can occur if initial connect operation succeeds but the remote endpoint does not terminate the connection during the SSL handshake. To protect against this situation, an app should set a timeout on the connect operation when requesting SSL/TLS and abort the operation if the timeout expires. For more information on setting a timeout using JavaScript on socket operations, see How to set timeouts on socket operations . For more information on setting a timeout using VB, C#, or C++ on socket operations, see How to set timeouts on socket operations .

    In a Windows Store app, the StreamSocket class supports connecting to a remote endpoint when proxies are required to complete the connection. This support for proxies is automatic and transparent to the app. Connecting through proxies is not supported when a local host address is specified, so the LocalHostName property passed in the endpointPair parameter must be null. For more detailed information, see the remarks on Support for proxies in the StreamSocket class reference.

    In a Windows Phone Store app, the StreamSocket class does not provide automatic support for proxies.

  • ConnectAsync(Windows.Networking.HostName,System.String)
    ConnectAsync(Windows.Networking.HostName,System.String)
    ConnectAsync(Windows.Networking.HostName,System.String)
    ConnectAsync(Windows.Networking.HostName,System.String)

    Starts an asynchronous operation on a StreamSocket object to connect to a remote network destination specified by a remote hostname and a remote service name.

    public IAsyncAction ConnectAsync(Windows.Networking.HostName,System.String)public IAsyncAction ConnectAsync(Windows.Networking.HostName,System.String)Public Function ConnectAsync(Windows.Networking.HostName,System.String) As IAsyncAction

    Parameters

    • remoteHostName

      The hostname or IP address of the remote network destination. For Bluetooth RFCOMM, this is a MAC address.

    • remoteServiceName
      System.String
      System.String
      System.String
      System.String

      The service name or TCP port number of the remote network destination. For Bluetooth RFCOMM, this is the Bluetooth address.

    Returns

    Remarks

    The remoteHostName and remoteServiceName parameters must be provided. If the remoteHostName is null or the remoteServiceName is null or an empty string, an error will occur.

    In a Windows Store app, the StreamSocket class supports connecting to a remote endpoint when proxies are required to complete the connection. This support for proxies is automatic and transparent to the app. For more detailed information, see the remarks on Support for proxies in the StreamSocket class reference.

    In a Windows Phone Store app, the StreamSocket class does not provide automatic support for proxies.

  • ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel)
    ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel)
    ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel)
    ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel)

    Starts an asynchronous operation on a StreamSocket object to connect to a remote destination specified by a remote hostname, a remote service name, and a SocketProtectionLevel.

    public IAsyncAction ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel)public IAsyncAction ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel)Public Function ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel) As IAsyncAction

    Parameters

    Returns

    Remarks

    The remoteHostName and remoteServiceName parameters must be provided. If the remoteHostName is null or the remoteServiceName is null or an empty string, an error will occur.

    When the protectionLevel parameter is set to a value that requires SSL or TLS, the socket connect operation may not timeout if the remote network destination does not support SSL or TLS. This can occur if initial connect operation succeeds but the remote host does not terminate the connection during the SSL handshake. To protect against this situation, an app should set a timeout on the connect operation when requesting SSL/TLS and abort the operation if the timeout expires. For more information on setting a timeout using JavaScript on socket operations, see How to set timeouts on socket operations . For more information on setting a timeout using VB, C#, or C++ on socket operations, see How to set timeouts on socket operations .

    In a Windows Store app, the StreamSocket class supports connecting to a remote endpoint when proxies are required to complete the connection. This support for proxies is automatic and transparent to the app. For more detailed information, see the remarks on Support for proxies in the StreamSocket class reference.

    In a Windows Phone Store app, the StreamSocket class does not provide automatic support for proxies.

  • ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter)
    ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter)
    ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter)
    ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter)

    Starts an asynchronous operation on a StreamSocket object on a specified local network adapter to connect to a remote destination specified by a remote hostname, a remote service name, and a SocketProtectionLevel.

    public IAsyncAction ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter)public IAsyncAction ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter)Public Function ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter) As IAsyncAction

    Parameters

    Returns

    Remarks

    The ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter) method binds to a network interface specified in the adapter parameter on the local computer and the remote hostname and service name specified in the remoteHostName and remoteServiceName parameters with the protection level specified in the protectionLevel parameter.

    The remoteHostName and remoteServiceName parameters must be provided. If the remoteHostName is null or the remoteServiceName is null or an empty string, an error will occur. If the adapter parameter is null, an error will occur.

    The name resolution mechanism used by the ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter) method is limited to the specified interface for the domain name system (DNS) namespace.

    Using the specified network adapter is on a best-effort basis. Systems with adapters configured in weak-host or forwarding modes may use an adapter other than the specified adapter.

    When the protectionLevel parameter is set to a value that requires SSL or TLS, the socket connect operation may not timeout if the remote network destination does not support SSL or TLS. This can occur if initial connect operation succeeds but the remote host does not terminate the connection during the SSL handshake. To protect against this situation, an app should set a timeout on the connect operation when requesting SSL/TLS and abort the operation if the timeout expires. For more information on setting a timeout using JavaScript on socket operations, see How to set timeouts on socket operations . For more information on setting a timeout using VB, C#, or C++ on socket operations, see How to set timeouts on socket operations .

    An app can retrieve a valid NetworkAdapter by inspecting a HostName instance (using the GetHostNames() method, for example) and retrieving the IPInformation object from the IPInformation property. The NetworkAdapter property can be used to retrieve the associated NetworkAdapter.

    In a Windows Store app, the StreamSocket class supports connecting to a remote endpoint when proxies are required to complete the connection. This support for proxies is automatic and transparent to the app. However, connecting through proxies is not supported when a specific network adapter is selected. So proxy support is disabled when the ConnectAsync(Windows.Networking.HostName,System.String,Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.Connectivity.NetworkAdapter) method is used. For more detailed information, see the remarks on Support for proxies in the StreamSocket class reference.

    In a Windows Phone Store app, the StreamSocket class does not provide automatic support for proxies.

  • EnableTransferOwnership(System.Guid)
    EnableTransferOwnership(System.Guid)
    EnableTransferOwnership(System.Guid)
    EnableTransferOwnership(System.Guid)

    Enables your app's background task to be triggered by the socket broker when traffic for this StreamSocket arrives while the app is not active.

    public void EnableTransferOwnership(System.Guid)public void EnableTransferOwnership(System.Guid)Public Function EnableTransferOwnership(System.Guid) As void

    Parameters

    • taskId
      System.Guid
      System.Guid
      System.Guid
      System.Guid

      The TaskId of the background task that will be triggered by the socket broker when traffic arrives for this StreamSocket.

  • EnableTransferOwnership(System.Guid,Windows.Networking.Sockets.SocketActivityConnectedStandbyAction)
    EnableTransferOwnership(System.Guid,Windows.Networking.Sockets.SocketActivityConnectedStandbyAction)
    EnableTransferOwnership(System.Guid,Windows.Networking.Sockets.SocketActivityConnectedStandbyAction)
    EnableTransferOwnership(System.Guid,Windows.Networking.Sockets.SocketActivityConnectedStandbyAction)

    Enables or disables the ability of your app's background task to be triggered by the socket broker when traffic for this StreamSocket arrives while the system is in connected standby.

    public void EnableTransferOwnership(System.Guid,Windows.Networking.Sockets.SocketActivityConnectedStandbyAction)public void EnableTransferOwnership(System.Guid,Windows.Networking.Sockets.SocketActivityConnectedStandbyAction)Public Function EnableTransferOwnership(System.Guid,Windows.Networking.Sockets.SocketActivityConnectedStandbyAction) As void

    Parameters

  • GetEndpointPairsAsync(Windows.Networking.HostName,System.String)
    GetEndpointPairsAsync(Windows.Networking.HostName,System.String)
    GetEndpointPairsAsync(Windows.Networking.HostName,System.String)
    GetEndpointPairsAsync(Windows.Networking.HostName,System.String)

    Gets a list of EndpointPair objects based on a remote hostname and remote service name that can be used to send TCP packets to a remote network destination.

    public static IAsyncOperation<EndpointPair>> GetEndpointPairsAsync(Windows.Networking.HostName,System.String)public static IAsyncOperation<EndpointPair>> GetEndpointPairsAsync(Windows.Networking.HostName,System.String)Public Static Function GetEndpointPairsAsync(Windows.Networking.HostName,System.String) As IAsyncOperation( Of EndpointPair )

    Parameters

    • remoteHostName

      The hostname of a service. The service might actually be hosted on multiple services, so that a DNS lookup returns multiple IP addresses for the various servers. This method returns one endpoint pair for each of the servers found by a DNS lookup.

    • remoteServiceName
      System.String
      System.String
      System.String
      System.String

      The name or port number of a remote service. Note that different servers might support the named service on different physical ports, so not all of the returned endpoints will use the same service port number.

    Returns

    • An asynchronous lookup operation. On successful completion, the returned list contains one EndpointPair for each remote host found, with one end point being one of the remote hosts and the other being the local host.

    Remarks

    This method gets a list of possible EndpointPair objects that can be used by a StreamSocket to send data to a remote network destination using TCP. The returned list is sorted so that the address pairs that are best suited for communication between two peers occur earlier in the list.

    A StreamSocket can use the list returned by this method to try and bind or connect to each EndpointPair object until a connection can be made. An EndpointPair object from the list would be used with the ConnectAsync(Windows.Networking.EndpointPair) methods

  • GetEndpointPairsAsync(Windows.Networking.HostName,System.String,Windows.Networking.HostNameSortOptions)
    GetEndpointPairsAsync(Windows.Networking.HostName,System.String,Windows.Networking.HostNameSortOptions)
    GetEndpointPairsAsync(Windows.Networking.HostName,System.String,Windows.Networking.HostNameSortOptions)
    GetEndpointPairsAsync(Windows.Networking.HostName,System.String,Windows.Networking.HostNameSortOptions)

    Gets a list of EndpointPair objects based on a remote hostname and remote service name and the sort order to be used.

    public static IAsyncOperation<EndpointPair>> GetEndpointPairsAsync(Windows.Networking.HostName,System.String,Windows.Networking.HostNameSortOptions)public static IAsyncOperation<EndpointPair>> GetEndpointPairsAsync(Windows.Networking.HostName,System.String,Windows.Networking.HostNameSortOptions)Public Static Function GetEndpointPairsAsync(Windows.Networking.HostName,System.String,Windows.Networking.HostNameSortOptions) As IAsyncOperation( Of EndpointPair )

    Parameters

    Returns

    Remarks

    The GetEndpointPairsAsync(Windows.Networking.HostName,System.String,Windows.Networking.HostNameSortOptions) method gets a list of possible EndpointPair objects that can be used by a StreamSocket to connect to a remote network destination. The returned list is sorted based on the sortOptions parameter.

    A StreamSocket can use the list returned by this method to try and bind or connect to each EndpointPair object until a remote destination can be reached. An EndpointPair object from the list would be used with the ConnectAsync(Windows.Networking.EndpointPair) method.

  • TransferOwnership(System.String)
    TransferOwnership(System.String)
    TransferOwnership(System.String)
    TransferOwnership(System.String)

    Transfers ownership of the StreamSocket to the socket brokering service, which monitors socket activity and notifies the app through a background task if there is any activity.

    public void TransferOwnership(System.String)public void TransferOwnership(System.String)Public Function TransferOwnership(System.String) As void

    Parameters

    • socketId
      System.String
      System.String
      System.String
      System.String

      A string the app uses to identify the transferred socket. The string should identify this socket uniquely within the app. When activity occurs on this socket, this string will be provided to the app to identify the socket.

    Remarks

    Your app should call this method to transfer ownership of the StreamSocket to the socket brokering service when the app is about to be suspended, or at the end of a background task. Your app should not access the StreamSocket object after calling this method, except when responding to notifications from the socket brokering service.

    Note

    This call fails if there is any pending I/O on the StreamSocket. Your code should call CancelIOAsync() to cancel any further new traffic, then handle all pending traffic, and then update the SocketActivityContext, before calling TransferOwnership(System.String).

  • TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext)
    TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext)
    TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext)
    TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext)

    Transfers ownership of the StreamSocket to the socket brokering service, which monitors socket activity and notifies the app through a background task if there is any activity. Specifies a new SocketActivityContext for the socket.

    public void TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext)public void TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext)Public Function TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext) As void

    Parameters

    • socketId
      System.String
      System.String
      System.String
      System.String

      A string the app uses to identify the transferred socket. The string should identify this socket uniquely within the app. When activity occurs on this socket, this string will be provided to the app to identify the socket.

    • data

      Use the SocketActivityContext to pass context information through the socket broker. When your app is notified by the broker of activity, this SocketActivityContext will be provided to your app to help establish the context in which you should handle the notification.

    Remarks

    Your app should call this method to transfer ownership of the StreamSocket to the socket brokering service when the app is about to be suspended, or at the end of a background task. Your app should not access the StreamSocket object after calling this method, except when responding to notifications from the socket brokering service.

    Note

    This call fails if there is any pending I/O on the StreamSocket. Your code should call CancelIOAsync() to cancel any further new traffic, then handle all pending traffic, and then update the SocketActivityContext, before calling TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext).

  • TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext,Windows.Foundation.TimeSpan)
    TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext,Windows.Foundation.TimeSpan)
    TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext,Windows.Foundation.TimeSpan)
    TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext,Windows.Foundation.TimeSpan)

    Transfers ownership of the StreamSocket to the socket brokering service, which monitors socket activity and notifies the app through a background task if there is any activity. Specifies a new SocketActivityContext and a keep alive time for the socket.

    public void TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext,Windows.Foundation.TimeSpan)public void TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext,Windows.Foundation.TimeSpan)Public Function TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext,Windows.Foundation.TimeSpan) As void

    Parameters

    Remarks

    Your app should call this method to transfer ownership of the StreamSocket to the socket brokering service when the app is about to be suspended, or at the end of a background task. Your app should not access the StreamSocket object after calling this method, except when responding to notifications from the socket brokering service.

    Note

    This call fails if there is any pending I/O on the StreamSocket. Your code should call CancelIOAsync() to cancel any further new traffic, then handle all pending traffic, and then update the SocketActivityContext, before calling TransferOwnership(System.String,Windows.Networking.Sockets.SocketActivityContext,Windows.Foundation.TimeSpan).

  • UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName)
    UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName)
    UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName)
    UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName)

    Starts an asynchronous operation to upgrade a connected socket to use SSL on a StreamSocket object.

    public IAsyncAction UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName)public IAsyncAction UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName)Public Function UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName) As IAsyncAction

    Parameters

    Returns

    Remarks

    The UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName) method can only be used to upgrade an already established connection made with a SocketProtectionLevel of PlainSocket.

    The typical order of operations to establish an SSL connection is as follows:

    The UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName) method can only be used for client connections. This method can't be used to upgrade a connection accepted by the StreamSocketListener to an SSL connection. The UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName) method only implements the client parts of the SSL protocol negotiation, not the server parts that would be needed to listen for and accept SSL connections.

    The UpgradeToSslAsync(Windows.Networking.Sockets.SocketProtectionLevel,Windows.Networking.HostName) method does not support the use of client certificates.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Capabilities

internetClient
privateNetworkClientServer
ID_CAP_NETWORKING [Windows Phone]
bluetooth.rfcomm

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.StaticAttribute

Details

Assembly

Windows.Networking.Sockets.dll