Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 550
Mike Flynn Avatar asked Oct 23 '25 18:10

Mike Flynn


1 Answers

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.

like image 61
Tim Lovell-Smith Avatar answered Oct 26 '25 17:10

Tim Lovell-Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!