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 | .NET MAUI
开发人员技术 | C#
{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 个人认为此答案很有帮助。

你的答案

问题作者可以将答案标记为“接受的答案”,这有助于用户了解已解决作者问题的答案。