Notify SignalR Server On Client Disconnected Accidentally (Disgracefully)

假如想象 提交于 2019-12-21 22:32:59

问题


I am setting my GlobalHost Configuration like this by following this answer to listen when the client is unreachable:

 GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(50);
 GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30);
 GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10);

And Overriding the OnDisconnected method in my HUB Class to set the client has been disconnected

 public override Task OnDisconnected(bool stopCalled) {
       /*My code for saving the information of disconnecting*/
        return base.OnDisconnected(stopCalled);      
    }

I am using Xamarin for android as a client and calling the Stop() method by overriding the OnStop() method of my activity, like this:

       protected override void OnStop()
        {

         //hubConnection.Stop(); previously I was using this but it takes too long to stop the hub connection in this way. so I wrote an explicit method and invoke it .

           Task hubconnection = serverHub.Invoke("StopConnection", new object[] { MethodToIdentifyDevice() }).ContinueWith(r =>
            {

            });


            base.OnStop();
        }

Secondly, I have written an explicit hubmethod to invoke when to notify my server explicitly that my client has stopped working. That method works at OnStop event.

My actual problem is that what if All of the stuff above is not able to call OnDisconnected method on activity stop or the application closed.

Is there anything I am missing which is not letting it to happen.

UPDATE: I have tried changing the Transport level to WebSocket but it is not provided in Xamarin SDK for SignalR as mentioned in the intellisense .

来源:https://stackoverflow.com/questions/40906789/notify-signalr-server-on-client-disconnected-accidentally-disgracefully

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!