3

I'm trying to connect using my smartphone (not emulator) to my Aspnet Core with SignalR backend. I added Cors to Startup.cs:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddCors(options =>
        {
            options.AddPolicy(MyAllowSpecificOrigins,
                builder => builder.SetIsOriginAllowed((host) => true)
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials());
        });

        services.AddSignalR();
    }

readonly string MyAllowSpecificOrigins = "AllowOrigins";
...

app.UseCors(MyAllowSpecificOrigins);

I tried to connect with an Angular frontend and it works well, and I would like to do the same with my Flutter App. Here's part of the code:

const url = 'http://192.168.1.87:44327/signalrtc';

class _MyHomePageState extends State<MyHomePage> {
  final hubConnection = HubConnectionBuilder().withUrl("$url").build();

  @override
  void initState() {
    super.initState();

    hubConnection.onclose((_) {
    print("Connessione persa");
    });

    hubConnection.on("ReceiveMessage", onReceiveMessage);
    startConnection();
  }

  void startConnection() async {
    print('start');
    await hubConnection.start();
  }

I'm only using Flutter SignalR package and I copied my local computer IPv4 to connect to my backend, because as I already said I'm not using an emulator so I can't insert 10.0.2.2, but if I try to run the App it will gives me that error. Both my computer and my smartphone are connected to the same network.

Any idea?

1 Answers1

0

SOLVED

I just installed Conveyor by Keyoti for Visual Studio.

ASP.NET Core - remote access from smartphone

With it you don't have to change any configuration, it just runs in the background and gives you a port you can use remotely, and also it can tunnel to the internet so you have a public URL if you like.

You only need to install it, run in debug mode and opening Keyoti you'll find another URL that you can use for your smartphone.

enter image description here

In the end I changed my URL in the Flutter project from:

const url = 'http://192.168.1.87:44327/signalrtc';

To:

const url = 'https://192.168.1.87:45456/signalrtc';

Basically is my IPv4 given from keyote but with another port.