I am developing real time client-server application using SignalR, ASP.NET and C#. I am using localhost as host and VS2103.
My questions are:
1. After I close server, on web-client the "Reconnect" event occurs and the "Disconnect" event occurs only after. Why?
2. The "Disconnect " occurs 30+ seconds after of unknown "Reconnect" . How to reduce this time?
3. I need the client to connect to the server on start. the "Reconnect" should occurs within fixed interval only. If "Reconnect" interval time is over and the client should connect as new client.
And generally - How to keep alive connection using SignalR in the right way?
I am using this code:
C#
Javascript
After Connect output:
After Close Server output:
My questions are:
1. After I close server, on web-client the "Reconnect" event occurs and the "Disconnect" event occurs only after. Why?
2. The "Disconnect " occurs 30+ seconds after of unknown "Reconnect" . How to reduce this time?
3. I need the client to connect to the server on start. the "Reconnect" should occurs within fixed interval only. If "Reconnect" interval time is over and the client should connect as new client.
And generally - How to keep alive connection using SignalR in the right way?
I am using this code:
C#
Code:
public override Task OnDisconnected() { clientList.RemoveAt(nIndex); Console.WriteLine("Disconnected {0}\n", Context.ConnectionId); return (base.OnDisconnected()); } public override Task OnReconnected() { Console.WriteLine("Reconnected {0}\n", Context.ConnectionId); return (base.OnReconnected()); }
Code:
$.connection.hub.reconnected(function () { // Html encode display name and message. var encodedName = $('<div />').text("heartbeat").html(); var now = new Date(); // Add the message to the page. $('#discussion').append('Reconnected to server: ' + now + '</br>'); }); $.connection.hub.disconnected(function () { // Html encode display name and message. var encodedName = $('<div />').text("heartbeat").html(); var now = new Date(); // Add the message to the page. $('#discussion').append('Disconnected from server: ' + now + '</br>'); });
Code:
message received from server http://localhost:8089/signalr : Fri Feb 21 2014 10:53:02
Code:
Reconnected to server: Fri Feb 21 2014 10:53:22 <-- Why, if i close server ??? Disconnected from server: Fri Feb 21 2014 10:53:53 <-- Why 40-50 seconds after server close ?