gpt4 book ai didi

Flutter AspNet Core SocketException (SocketException : OS Error: Connection timed out, errno = 110, address = 192.168.1.87, port = 46186)

转载 作者:行者123 更新时间:2023-12-05 07:08:08 26 4
gpt4 key购买 nike

我正在尝试使用我的智能手机(不是模拟器)连接到我的带有 SignalR 后端的 Aspnet Core。我将 Cors 添加到 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);

我尝试连接一个 Angular 前端,它运行良好,我想对我的 Flutter 应用程序做同样的事情。这是部分代码:

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();
}

我只使用 Flutter SignalR package我复制了我的本地计算机 IPv4 以连接到我的后端,因为正如我已经说过的,我没有使用模拟器,所以我无法插入 10.0.2.2,但是如果我尝试运行该应用程序,它会给我这个错误。我的电脑和智能手机都连接到同一个网络。

有什么想法吗?

最佳答案

已解决

我刚刚为 Visual Studio 安装了 Conveyor by Keyoti

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.

您只需安装它,在 Debug模式下运行并打开 Keyoti,您会发现另一个可用于您的智能手机的 URL。

enter image description here

最后我把我在Flutter项目中的URL改成了:

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

收件人:

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

基本上我的 IPv4 是从 keyote 给出的,但是有另一个端口。

关于Flutter AspNet Core SocketException (SocketException : OS Error: Connection timed out, errno = 110, address = 192.168.1.87, port = 46186),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61932097/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com