When iOS 17 sends UDP, System Net Sockets SocketException (65): Norout to host

于晏 彭 5 信誉分
2024-04-19T09:11:30.24+00:00

I am using Maui and NET 8 in Visual Studio 2022, And implement UDP and TCP messages sent on iOS 17. There is an issue with UDP not being able to send messages and displaying error messages: System NET Sockets SocketException (65): No route to host, Sent peer-to-peer information, not multicast,but everything is normal on Windows and Android, with the same WiFi assigned IP address and port. The code is as follows:

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);

The code is in udpClient.Send(), error System Net Sockets SocketException (65): Norout to host. Please provide some suggestions. Thank you

I tried to configure the following permissions in info.plist:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <
<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>

Trying is useless.

I tried using a temporary distribution package for installation, but it didn't solve the problem. Even using a hot restart doesn't work. I used software to ping the WiFi router address on my iOS 17 phone and it was successful.Please give me some suggestions.

.NET MAUI
.NET MAUI
一种 Microsoft 开源框架,用于构建跨移动设备、平板电脑、台式机的原生设备应用程序。
37 个问题
C#
C#
一种面向对象的类型安全的编程语言,它起源于 C 语言系列,包括对面向组件的编程的支持。
106 个问题
{count} 票

1 个答案

排序依据: 非常有帮助
  1. 于晏 彭 5 信誉分
    2024-04-24T08:48:50.8733333+00:00

    In fact, when using TCP and UDP peer-to-peer communication on iOS, it is necessary to confirm whether the application has enabled the "wireless data" permission. The steps are: Settings ->Your application ->Select wireless LAN and cellular network

    1 个人认为此答案很有帮助。