Mike Flynn
Mike Flynn

Reputation: 24325

SignalR and failed websocket connection, but still works

I am currently getting this error below in Chrome console, but it still connects successfully with SignalR. Any reason why I am getting this error?

JS Hub Connection

scheduleHub = $.connection.scheduleHub;
        scheduleHub.client.viewing = function (name, message) {
            app.showWarning(message, name, function () {
                app.refreshHash();
            });
        };

        if ($.connection.hub && $.connection.hub.state === $.signalR.connectionState.disconnected) {
            $.connection.hub.qs = { "eventid": options.eventId };
            $.connection.hub.start()
                .done(function () {
                    alert('Connected');
                    //scheduleHub.server.viewing('wow', 'test');
                })
                .fail(function() { alert('Could not Connect!'); });
        }

Chrome Console

WebSocket connection to 'ws://localhost:2222/signalr/connect?transport=webSockets&clientProtocol=1.4&eventid=23919&connectionToken=CV3wchrj88t6FdjgA%2BREdzEDIw0rhW6r2aUrb%2BI8qInsb3Y9BqQSOscPxfAZ2g0Dxl704usqdBBn%2BNSFKpjVNOtwASndOweD1kGWPCkWEbtJBMu%2B&connectionData=%5B%7B%22name%22%3A%22schedulehub%22%7D%5D&tid=5' failed: Error during WebSocket handshake: Unexpected response code: 500

enter image description here

Upvotes: 4

Views: 8579

Answers (1)

Tim Lovell-Smith
Tim Lovell-Smith

Reputation: 16125

Web Sockets initially starts by negotiating the websockets connection over HTTP. During this HTTP handshake, the web server probably raised an exception, anyway, it returns HTTP Status Code 500. Without a successful HTTP response, Chrome is unable to continue negotiating the web sockets connection.

Since SignalR works over multiple transports, and not just websockets, once websockets connection failed, it will have automatically have switched to try some other transport, like forever frame or polling, which is why your connection still works.

Upvotes: 6

Related Questions