Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket Communication on UWP (Universal Windows Platform)

Tags:

c#

sockets

uwp

What I want to implement is UWP-based programs and other C# programs are trying to communicate with Socket on one PC (Windows 10 Pro).

I have tried to make UDP communication module using DatagramSocket class and TCP communication module using StreamSocket class (https://msdn.microsoft.com/ko-kr/windows/uwp/networking/sockets) and it seems that module is not working properly.

In the Windows UWP example program and some developer forums, I saw a statement that it is impossible that socket communication between other programs on the same device.

I am wondering if it was the right I understood.

Also, if it is right, Would you recommend other ways to solve this problem?

like image 207
KOceanSky Avatar asked Feb 21 '26 23:02

KOceanSky


1 Answers

I saw a statement that it is impossible that socket communication between other programs on the same device

It is right. According to the note of DatagramSocket official sample:

Network communications using an IP loopback address cannot normally be used for interprocess 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.

We cannot communicate a uwp app with other apps in a same machine.

Also, if it is right, Would you recommend other ways to solve this problem?

By testing on my side, if you use a c# console project as server and a uwp app as client, they can communicate successfully both with StreamSocket and DatagGramSocket. But following special steps need to pay attention to let it work.

  • Please ensure the Internet(Client&Server) and Private Internet(Client&Server) capabilities are enabled.

  • Run the server side as administrator.

  • Allow the network access promoted by windows when you run the server.

I wrote a demo which contains server side and client side of UDP and TCP. You can download here for testing.

And the results.

enter image description here

Although this can work, I recommend you to not use except for developing purpose.

like image 189
Sunteen Wu Avatar answered Feb 23 '26 12:02

Sunteen Wu