iOS 17 发送 UDP 时,System Net Sockets SocketException (65): Norout to host

问题描述 投票:0回答:1

我在 Visual Studio 2022 中使用 Maui 和 NET 8,并实现在 iOS 17 上发送的 UDP 和 TCP 消息。存在 UDP 无法发送消息并显示错误消息的问题:System NET Sockets SocketException (65): No路由到主机,发送点对点信息,不是组播,但在 Windows 和 Android 上一切正常,具有相同的 WiFi 分配的 IP 地址和端口。代码如下:

TcpListener tcpListener = new TcpListener(IPAddress.Parse("The IP address of WiFi
"), 8989);
tcpListener.Start();

IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse("WiFi router address
"), 57788);
udpClient.Send(requestBytes, requestBytes.Length, remoteEP);

await Task.Delay(20);
TcpClient udpClient.Client.ReceiveTimeout = 3000;
byte[] responseBytes = udpClient.Receive(ref remoteEP);

代码在udpClient.Send()中,错误System Net Sockets SocketException (65): Norout to host。请提供一些建议。谢谢你

我尝试在info.plist中配置以下权限:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsLocalNetworking</key>
    <true/>
</dict>
<key>NSLocalNetworkUsageDescription</key>
<string>This app needs access to the local network to communicate with devices.</string>

尝试是没有用的。

我尝试使用临时分发包进行安装,但没有解决问题。即使使用热重启也不起作用。我用软件在我的iOS 17手机上ping WiFi路由器地址,成功了。请给我一些建议。

c# ios maui .net-8.0
1个回答
0
投票

实际上,在iOS上使用TCP和UDP点对点通信时,需要确认应用程序是否启用了“无线数据”权限。步骤是:设置 -> 您的应用程序 -> 选择无线局域网和蜂窝网络

© www.soinside.com 2019 - 2024. All rights reserved.