Socket Communication on UWP (Universal Windows Platform)

試著忘記壹切 提交于 2019-12-30 07:43:09

问题


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?


回答1:


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.

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



来源:https://stackoverflow.com/questions/40926902/socket-communication-on-uwp-universal-windows-platform

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!