Supports network communication using a TCP stream socket.
Syntax
var streamSocket = new Windows.Networking.Sockets.StreamSocket();
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- DualApiPartitionAttribute()
- MarshalingBehaviorAttribute(Agile)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
Members
The StreamSocket class has these types of members:
Constructors
The StreamSocket class has these constructors.
| Constructor | Description |
|---|---|
| StreamSocket | Creates a new StreamSocket object. |
Methods
The StreamSocket class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| Close [C++, JavaScript] | Closes the StreamSocket object. |
| ConnectAsync(EndpointPair) | Starts an asynchronous operation on a StreamSocket object to connect to a remote network destination specified as an EndpointPair object. |
| ConnectAsync(EndpointPair, 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. |
| ConnectAsync(HostName, 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. |
| ConnectAsync(HostName, String, SocketProtectionLevel) | Starts an asynchronous operation on a StreamSocket object to connect a remote destination specified by a remote hostname, a remote service name, and a SocketProtectionLevel. |
| Dispose [C#, VB] | Performs tasks associated with freeing, releasing, or resetting unmanaged resources. |
| UpgradeToSslAsync | Starts an asynchronous operation to upgrade a connected socket to use SSL on a StreamSocket object. |
Properties
The StreamSocket class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets socket control data on a StreamSocket object. | |
| Read-only | Gets socket information on a StreamSocket object. | |
| Read-only | Gets the input stream to read from the remote destination on a StreamSocket object. | |
| Read-only | Gets the output stream to write to the remote host on a StreamSocket object. |
Remarks
The StreamSocket class provides support for network communication using a TCP stream socket.
The StreamSocket object is also used in conjunction with the StreamSocketListener object to listen for TCP connections. The StreamSocket object is returned by the Socket property on the ConnectionReceived event when a StreamSocketListener object receives a TCP connection request.
The typical order of operations is as follows:
- Create the StreamSocket.
- Get a StreamSocketControl object using the Control property and set any properties on the StreamSocketControl object before calling one of the ConnectAsync methods.
- Call one of the ConnectAsync methods to establish a connection with the remote endpoint. If an SSL/TLS connection is required immediately, this can be specified using some of the ConnectAsync methods. If an SSL/TSL connection is desired after sending and receiving some initial data, then the UpgradeToSslAsync method can be called later to upgrade the connection to use SSL.
- Get the OutputStream property to write data to the remote host.
- Get the InputStream property to read data from the remote host.
- Read and write data as needed.
- Call the Close method to abort any pending operations and release all unmanaged resources associated with the StreamSocket object.
Note The Close is used by Windows Store apps written in JavaScript. For apps written using the .NET Framework 4.5 in C# and VB.NET, the Close method is exposed as the Dispose() method on the StreamSocket. For apps written in C++, the Close method will be called when using the delete keyword on the object.
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps, desktop apps] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps, desktop apps] |
|
Minimum supported phone | Windows Phone 8 |
|
Namespace |
|
|
Metadata |
|
|
DLL |
|
|
Capabilities |
|
See also
- Other resources
- Connecting to network services (Windows Store apps using JavaScript and HTML)
- Connecting to network services (Windows Store apps using C#/VB/C++ and XAML)
- How to secure socket connections with TLS/SSL (Windows Store apps using JavaScript and HTML)
- How to secure socket connections with TLS/SSL (Windows Store apps using C#/VB/C++ and XAML)
- How to set background connectivity options
- How to use advanced socket controls (Windows Store apps using JavaScript and HTML)
- How to use advanced socket controls (Windows Store apps using C#/VB/C++ and XAML)
- Quickstart: Connecting to a network resource with a stream socket (Windows Store apps using JavaScript and HTML)
- Quickstart: Connecting to a network resource with a stream socket (Windows Store apps using C#/VB/C++ and XAML)
- Supporting proximity and tapping
- Troubleshoot and debug network connections
- Reference
- ControlChannelTrigger
- IClosable
- Object
- SetSocketMediaStreamingMode
- StreamSocketListener
- StreamSocketListener.ConnectAsync
- Samples
- ControlChannelTrigger StreamSocket sample
- StreamSocket sample
Build date: 2/25/2013