I have a .NET MAUI implementation of System.Net.Sockets that runs fine on Windows, but when run on Android 10, the call to Dns.GetHostEntry("GAI-W10-Dev1"); throws an exception: System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: 'hostname nor servname provided, or not known'.
An attempt to skip the GetHostEntry call by just providing the name and port to Socket.Connect failed in the same manner.
The Android device is connected to Wi-Fi and is able to browse the web, so the network stack is fully operational.
What am I missing that is preventing Android from executing the socket calls correctly?
I am building with VS 2022 17.3.2
My Android manifest is as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
And my C# socket code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace MauiApp1
{
internal class YesaSocket
{
internal IPAddress serverAddress = null;
IPEndPoint serverIpe = null;
Socket server = null;
internal bool Open()
{
bool bReturn = false;
while (true)
{
IPHostEntry hostEntry = Dns.GetHostEntry("GAI-W10-Dev1");
if (hostEntry == null)
break;
foreach (IPAddress address in hostEntry.AddressList)
{
if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
serverAddress = address;
break;
}
}
if (serverAddress == null)
break;
serverIpe = new IPEndPoint(serverAddress, 5150);
if (serverIpe == null)
break;
server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
if (server == null)
break;
server.Connect(serverIpe);
if (server.Connected)
bReturn = true;
break;
}
return bReturn;
}
internal bool SendRequest(byte[] pRequest, int iRequestSize) {
return true;
}
internal void Close()
{
server.Close();
return;
}
}
}