Is there any way to stop polling server in SignalR? I want to stop polling server if error occurs. Polling hubs is started with $.connection.hub.start()
, so I assumed that it could be stopped with $.connection.hub.stop()
or something like that. But it doesn't seem to work, polling continues even after calling stop()
. Is there another way to stop pollling?
<script type="text/javascript">
var chatHub = $.connection.chatHub;
var connection = $.connection.hub;
chatHub.addMessage = function (message) {
$('#messages').append('<li>' + message + '</li>');
};
connection.error(function (error) {
$('#messages').append('<li>' + "error connecting: closing connnection" + '</li>');
connection.stop(); //This doesn't seem to work
});
connection.start();
</script>
A SignalR connection can end in any of the following ways: If the client calls the Stop method, a stop message is sent to the server, and both client and server end the SignalR connection immediately.
SignalR is a Microsoft framework specifically designed to facilitate real-time client/server communication. It provides an effective implementation of long polling that doesn't have a deep impact on the server, and at the same time ensures that clients are appropriately updated about what's going on remotely.
Timeout configuration for SignalR can be set in Application_Start method of Global class in Global. asax. cs file. // Wait a maximum of 30 minutes after a transport connection is lost // before raising the Disconnected event to terminate the SignalR connection.
If you're using hubs you can stop the hub's connection:
$.connection.hub.stop();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With