首页 > 解决方案 > 服务器实时调用客户端(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();
        }

标签: c#xamarin.formswebsocket

解决方案


推荐阅读