简体   繁体   English

为什么在 UWP 中必须使用 StreamSocketListener 而不是 TcpListener,尽管 UWP 是 .NET Core 的子集,并且 TcpListener 在 UWP 中可用?

[英]Why must StreamSocketListener be used in UWP instead of TcpListener, although UWP is a subset of .NET Core and TcpListener is available in UWP?

As mentioned here and here , the usage of TcpListener ist not possible in UWP.如此此处所述,在 UWP 中不可能使用 TcpListener。 Instead, StreamSocketListener has to be used.相反,必须使用 StreamSocketListener。

But after a relatively long research, I didn't understand why?但是经过比较长时间的研究,我不明白为什么?

Since UWP is actually a subset of of .NET Core, using TcpListener should be possible in UWP also!由于 UWP 实际上是 .NET Core 的一个子集,因此在 UWP 中也应该可以使用 TcpListener!

Just for testing, I even created a UWP project, tried to use System.Net.Sockets.TcpListener in the code and there was no problem.只是为了测试,我什至创建了一个UWP项目,尝试在代码中使用System.Net.Sockets.TcpListener,没有问题。 I didn't write the complete code and didn't try to run the server, but only tried to reference System.Net.Sockets.TcpListener from within a UWP project and this was possible.我没有编写完整的代码,也没有尝试运行服务器,只是尝试从 UWP 项目中引用 System.Net.Sockets.TcpListener,这是可能的。 And no wonder because even according to Microsoft docs ( https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcplistener?view=netcore-1.0 ) the class is available starting from .NET Core 1.0.这也难怪,因为即使根据 Microsoft 文档( https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcplistener?view=netcore-1.0 ),该类也可以从 .NET 开始使用核心 1.0。

Newer versions of UWP support .NET Standard 2.0, which includes many APIs that were not available in earlier versions of UWP.较新版本的 UWP 支持 .NET Standard 2.0,其中包括许多在较早版本的 UWP 中不可用的 API。

See eg: https://devblogs.microsoft.com/dotnet/announcing-uwp-support-for-net-standard-2-0/参见例如: https : //devblogs.microsoft.com/dotnet/annoucing-uwp-support-for-net-standard-2-0/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM