SignalR connection error

I have a simple client chat project that works using SignalR and MVC, which is almost identical to ASP.Net One (I'm just experimenting - the client code is identical). I linked the following to see how they happen:

$.connection.hub.stateChanged(function(state){console.log(state)}); 

The connections work fine, but I noticed that if I turn off IIS Express and watch the console in Chrome, I see the following:

 //As you would expect the state goes from connected to connecting Object {oldState: 1, newState: 2} //Then it times out after about 30 secs and throws this awesomeness at the console WebSocket connection to 'ws://localhost:61623/signalr?transport=webSockets&connectionToken=VDF640emz7PFMToC6vxle_5-7QS5dZMszV4SPbQO7EFEmSSsITnwKsZreqfl4MGq8TXitG2xB5F-2ZdHp-2t3shPzN2hemTY1ZmEWlB8NOn5orUVexaSoARk9XjEO5B00&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&messageId=B%2C7%7CL%2C0%7CM%2C0%7CN%2C0&tid=0' failed: WebSocket is closed before the connection is established. jquery.signalR-1.0.1.js:1117 //Reconnecting to Disconnecting - so why the error above? Object {oldState: 2, newState: 4} //Then radio silence if I start IIS again... :? //As you would expect the state goes from connected to connecting Object {oldState: 1, newState: 2} //Then it times out after about 30 secs and throws this awesomeness at the console WebSocket connection to 'ws://localhost:61623/signalr?transport=webSockets&connectionToken=VDF640emz7PFMToC6vxle_5-7QS5dZMszV4SPbQO7EFEmSSsITnwKsZreqfl4MGq8TXitG2xB5F-2ZdHp-2t3shPzN2hemTY1ZmEWlB8NOn5orUVexaSoARk9XjEO5B00&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&messageId=B%2C7%7CL%2C0%7CM%2C0%7CN%2C0&tid=0' failed: WebSocket is closed before the connection is established. jquery.signalR-1.0.1.js:1117 //Reconnecting to Disconnecting - so why the error above? Object {oldState: 2, newState: 4} //Then radio silence if I start IIS again... VDF640emz7PFMToC6vxle_5-7QS5dZMszV4SPbQO7EFEmSSsITnwKsZreqfl4MGq8TXitG2xB5F-2ZdHp-2t3shPzN2hemTY1ZmEWlB8NOn5orUVexaSoARk9XjEO5B00 & connectionData =% 5B% 7B% 22name% //As you would expect the state goes from connected to connecting Object {oldState: 1, newState: 2} //Then it times out after about 30 secs and throws this awesomeness at the console WebSocket connection to 'ws://localhost:61623/signalr?transport=webSockets&connectionToken=VDF640emz7PFMToC6vxle_5-7QS5dZMszV4SPbQO7EFEmSSsITnwKsZreqfl4MGq8TXitG2xB5F-2ZdHp-2t3shPzN2hemTY1ZmEWlB8NOn5orUVexaSoARk9XjEO5B00&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&messageId=B%2C7%7CL%2C0%7CM%2C0%7CN%2C0&tid=0' failed: WebSocket is closed before the connection is established. jquery.signalR-1.0.1.js:1117 //Reconnecting to Disconnecting - so why the error above? Object {oldState: 2, newState: 4} //Then radio silence if I start IIS again... % 2C7% 7CL //As you would expect the state goes from connected to connecting Object {oldState: 1, newState: 2} //Then it times out after about 30 secs and throws this awesomeness at the console WebSocket connection to 'ws://localhost:61623/signalr?transport=webSockets&connectionToken=VDF640emz7PFMToC6vxle_5-7QS5dZMszV4SPbQO7EFEmSSsITnwKsZreqfl4MGq8TXitG2xB5F-2ZdHp-2t3shPzN2hemTY1ZmEWlB8NOn5orUVexaSoARk9XjEO5B00&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&messageId=B%2C7%7CL%2C0%7CM%2C0%7CN%2C0&tid=0' failed: WebSocket is closed before the connection is established. jquery.signalR-1.0.1.js:1117 //Reconnecting to Disconnecting - so why the error above? Object {oldState: 2, newState: 4} //Then radio silence if I start IIS again... 

2 Questions:

How to avoid an error when trying to reconnect?

Why is SignalR not trying to connect to IIS? I was impressed that this was the point of technology ...

EDIT: The same thing happens in FireFox.

+4
source share
1 answer

In the end, the connection will die and stop trying again. You can constantly connect to this method from SignalR documents.

How to connect constantly

How to connect constantly

In some applications, you can automatically recover after it has been lost, and the attempt to reconnect has timed out. To do this, you can call the "Start" method from your private event handler (a disabled event handler on JavaScript clients). You may want to wait a while before calling Start to avoid doing this too often when the server or physical connection is unavailable. The following code sample is intended for a JavaScript client using the generated proxy server.

 $.connection.hub.disconnected(function() { setTimeout(function() { $.connection.hub.start(); }, 5000); // Restart connection after 5 seconds. }); 
+10
source

Source: https://habr.com/ru/post/1479907/


All Articles