.Net Maui Can't connect to localhost from Android Emulator
Hi all,
I need to connect to my server app (Elixir/Phoenix) over websockets, and currently have iOS and MacOS builds connecting fine, but I am getting the following error when running the app in the Android emulator:
Fatal|WebSocket.connect|System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (111): Connection refused [::ffff:127.0.0.1]:4002
Has anyone come across this before?
I'm using PhoenixSharp to connect to my server app. When I build with it I get the following warning:
: Warning NU1701: Package 'WebSocketSharp 1.0.3-rc11' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. (NU1701) (Phoenix)
Could this relate to the problem with Android?
Here's the relevant code (which I expected to work on all devices):
using Phoenix;
var socketOptions = new Socket.Options(new JsonMessageSerializer());
var socketAddress = "ws://localhost:4002/socket";
var socketFactory = new WebsocketSharpFactory();
var socket = new Socket(socketAddress, new Dictionary<string, string>(), socketFactory, socketOptions);
socket.connect();
Visual Studio 2022 (Mac)
.Net 7.0.200
Android Pixel 5 (Api 33)
I'm happy to provide any additional info that may help.
Many thanks
Paul
Edit: The warning mentioned above is not the issue. I've resolved that now. Also, I can connect to my remote server fine from the Android emulator, I just can't get to localhost on my dev machine.