gpt4 book ai didi

c# - 在 UWP TcpListener AcceptTcpClientAsync 中不起作用

转载 作者:行者123 更新时间:2023-11-30 18:15:13 26 4
gpt4 key购买 nike

我正在移植一些 TcpListener/TcpClient/etc 代码以在 UWP 上工作。但是,在通用 Windows C# 应用程序中工作的最基本操作在 UWP 下对我来说失败了。

最基本的操作,例如等待 TcpClient 失败:

private async Task TestTcpListening()
{
Debug.WriteLine("Creating TcpListneer");
int portNumber = 8554;
TcpListener listener = new TcpListener(IPAddress.Any, portNumber);
listener.Start();

while(true)
{
Debug.WriteLine("Waiting on TcpListener to accept client");
TcpClient client = await listener.AcceptTcpClientAsync();
Debug.WriteLine(string.Format("We got a client! {0}", client));
}
}

如果我在通用 Windows 控制台应用程序中运行此代码,当我触发本地主机 URL 时,“我们有一个客户端”位会运行。如果它在 UWP 应用程序中运行,它将永远等待并且调用应用程序超时。

注意事项:

  • 我在 Package.appxmanifest 中选择了Internet(客户端和服务器)InternetPrivate Networks 功能
  • 我正在移植一个 RTSP 服务器,它作为一个通用的 Windows 应用程序运行良好。因此,我使用的 URI 是“rtsp://localhost:8554”。当构建为命令行 Windows 应用程序时,将 VLC 指向该 URI 时,上述代码按预期工作。相同代码的 UWP 版本永远等待,VLC 超时。
  • 我是 Windows 的新手,所以我还不知道我不知道什么。

想法:

  • 我是否需要以某种方式启用对应用程序的“rtsp:”协议(protocol)访问?我不希望应用程序在 rtsp: url 被点击时打开。我只想处理传入的连接。

最佳答案

作为 Windows 开发的新手,尤其是 UWP,我不知道环回限制。目前,为了测试我的 RTSP 端口,在同一网络上的另一台计算机上使用 VLC 解决了我的上述问题。

关于c# - 在 UWP TcpListener AcceptTcpClientAsync 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48818657/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com