This sample shows how to use the Socket Activity Stream Socket API to keep a socket connection alive beyond the lifetime of the application.
This sample connects to a server listening on TCP port 40404. The application can be terminated but the connection to the server will remain alive and will get background notifications if the server sends messages on the connection.
This sample requires the following capabilities:
- Private Networks (Client & Server) - If the server it connects to is in intranet then it requires private Network capabilities.
For more information on network capabilities, see How to set network capabilities.
Note This sample uses IP loopback. Network communications using an IP loopback address cannot normally be used for inter process communication between a Universal Windows Platform (UWP) app and a different process (a different UWP app or a desktop app) because this is restricted by network isolation. Network communication using an IP loopback address is allowed within the same process for communication purposes in a UWP app.
How to configure network isolation capabilities
Client: Windows 10
Server: Windows Server 2016 Technical Preview
Phone: Windows 10
- If you download the samples ZIP, be sure to unzip the entire archive, not just the folder with the sample you want to build.
- Start Microsoft Visual Studio 2015 and select File > Open > Project/Solution.
- Starting in the folder where you unzipped the samples, go to the Samples subfolder, then the subfolder for this specific sample, then the subfolder for your preferred language (C++, C#, or JavaScript). Double-click the Visual Studio 2015 Solution (.sln) file.
- Press Ctrl+Shift+B, or select Build > Build Solution.
The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it.
- Select Build > Deploy Solution.
- To debug the sample and then run it, press F5 or use Debug > Start Debugging. To run the sample without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.
This sample requires two computers that can connect to each other over a network. One computer will play the role of the client, while the other computer will play the role of the server.
To deploy this sample after building it, select Deploy Solution from the Build menu.
The sample must be deployed to both the client and server computers.
To run the sample, first the start the server app on the server computer. It will wait for the clients to connect.
After the server app has started, start the client app on the client computer.
-
Specify the server name in the text box and click connect.
-
Once a connection is established, you can terminate the client application.
Once the client is connected, you can send messages from the server application text box. The client displays received messages as toast notifications.