StreamSocket.ConnectAsync(HostName, String, SocketProtectionLevel, NetworkAdapter) | connectAsync(HostName, String, SocketProtectionLevel, NetworkAdapter) method
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.
streamSocket.connectAsync(remoteHostName, remoteServiceName, protectionLevel, adapter).done( /* Your success and error handlers */ );
The hostname or IP address of the remote network destination. For Bluetooth RFCOMM, this is a MAC address.
The service name or TCP port number of the remote network destination. For Bluetooth RFCOMM, this is the Bluetooth address.
The protection level that represents the integrity and encryption for the StreamSocket object.
The local network adapter to use for the connect operation on the StreamSocket object.
An asynchronous connect operation on a StreamSocket object.
The ConnectAsync(Hostname, String, SocketProtectionLevel, 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(Hostname, String, SocketProtectionLevel, 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.
An app can retrieve a valid NetworkAdapter by inspecting a HostName instance (using the NetworkInformation.GetHostNames method, for example) and retrieving the IPInformation object from the Hostname.IPInformation property. The IPInformation.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(HostName, String, SocketProtectionLevel, 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.
Minimum supported client
Minimum supported server
|Windows Server 2012 R2|
Minimum supported phone
|Windows Phone 8.1 [Windows Runtime apps only]|
- Other resources
- How to set timeouts on socket operations (HTML)
- How to set timeouts on socket operations (XAML)
- ConnectAsync(HostName, String)
- ConnectAsync(EndpointPair, SocketProtectionLevel)
- ConnectAsync(HostName, String, SocketProtectionLevel)