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?