c# - 服务器实时调用客户端(Xamarin Forms e Aspnet Core)
问题描述
我在 AspNet Core C# 中有一个应用程序(服务器),当服务器上有 IP 交换时,它需要通知 Xamarin Forms(客户端)应用程序。我目前使用 SignalR 进行实时通信。但是当它更改服务器的 IP 时,这种通信就会丢失。目前我无法使用 DNS 名称。我该如何解决这个问题?是否可以使用 SignalR 执行此操作,还是应该寻找其他组件?
//Client Code
public static async Task SetupSignalR()
{
try
{
if (hubConnection == null || hubConnection.State == ConnectionState.Disconnected)
{
hubConnection = new HubConnection(Configuracao.ServerUrl + "");
var notificaoHub = hubConnection.CreateHubProxy("NotificacaoHub");
var inicializar = App.Container.Get<IInicializacaoService>();
notificaoHub.On("NotificacaoTrocaIpServidor", NotificacaoTrocaIpServidor);
await hubConnection.Start();
}
}
catch (Exception ex)
{
App.RegistrarErro(ex.Message, ex);
}
}
//Server Code
public void ConfigurarIpServidor(DtoConfigurarIpServidorRequest dto)
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<NotificacaoHub>();
context.Clients.All.NotificacaoTrocaIpServidor();
}
解决方案
推荐阅读
- javascript - 在 SWR 获取请求中使用 Next.js 动态路由查询对象
- flutter - Flutter 包“just_audio”抛出异常
- javascript - TypeError:无法读取未定义的属性“当前”
- javascript - React 更改后 Laravel 视图未更新
- java - 使用 getContentpane 和 FlowLayout 对 Layout 进行更改,但它不起作用,为什么?
- c++ - 有没有办法将一些 unique_ptr 的右值引用传递给线程池
- javascript - React/TypeScript - 类型 'false | 元素'不可分配给类型'元素'
- javascript - 使用Javascript检查内容时出现问题是json类型
- c++ - 重载解析适用于函数,但不适用于隐式构造函数参数
- python - 为什么这段代码不继续留在条件循环中不止一次迭代?