问题描述
我要实现的是基于UWP的程序,其他C#程序正在尝试与一台PC(Windows 10 Pro)上的Socket通信.
我试图使用DatagramSocket类和UDP使用StreamSocket类来创建UDP通信模块(
我编写了一个演示,其中包含UDP和TCP的服务器端和客户端.您可以在
尽管这可以工作,但我建议您不要出于开发目的而使用它.
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?
It is right. According to the note of DatagramSocket official sample:
We cannot communicate a uwp app with other apps in a same machine.
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.
这篇关于UWP(通用Windows平台)上的套接字通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!