1

I want to update my grid with latest alert messages added by Admin. I am using signalr and all hub related code I have added successfully.

It's also starting signalr connection but at the same time throwing below error

jquery.signalR-2.2.1.min.js:9 WebSocket connection to 'ws://localhost:58739/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=2h%2BQtKQ99bX%2Ffe8JT2UI1rbXQjfRYvt0MU9%2Fb7t6UzDpQcOGZ111owEUFVTQefgDA5EJ2e2C0HEHRRa%2BJSZ2Wz9rggWDARFiHUgdNihnhTlrpEw5fAK7v6wRfrkT1PiQ4VvxuHJRaIL3JxbxCs4tYlq%2F8qgAqA8UVNVB6e9CHkk%3D&connectionData=%5B%7B%22name%22%3A%22alertsmessageshub%22%7D%5D&tid=3' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET

Below is script code in my view to update grid messages using signalr

 $(function () {
   debugger;
   // Declare a proxy to reference the hub.
   var notifications = $.connection.alertsMessagesHub;

   //debugger;
   // Create a function that the hub can call to broadcast messages.
   notifications.client.updateMessages = function () {
       getAllMessages()
   };

   // Start the connection.
   $.connection.hub.start().done(function () {
       alert("connection started")
       getAllMessages();
   }).fail(function (e) {
       alert(e);
   });
});

Here, in above code it's showing alert that Connection Started and also calling getAllMessages() javascript method but then after in chrome development tool I am seeing above error.

Now, Below is my AlertsMessagesHub code

public static void SendMessages()
{
  IHubContext context = GlobalHost.ConnectionManager.GetHubContext<AlertsMessagesHub>();
     context.Clients.All.updateMessages();
}

Can anyone guide me what mistake I am doing or let me know if additional information required?

My .Net Target Framework is 4.5.1 and I am using signalr 2.2.1 and jquery : 2.1.4

Mukesh Ram
  • 6,248
  • 4
  • 19
  • 37
NeilSah
  • 31
  • 8
  • Is this on your development PC or a server? What version of Windows are you using? Is it reverting to Server-Sent-Events (or Forever Frames)? – thab Sep 23 '16 at 09:34
  • Yeah, it's my development PC and I am testing it on localhost running from visual studio. I am using VS-2015 and my OS : windows 8.1 This code I have to publish on azure server if working fine. – NeilSah Sep 23 '16 at 09:41
  • Hmmm I know Windows 7 doesn't support WebSockets. I thought Windows 8.1 did. I use Windows 10 Dev and WebSockets works find in vs 2015. Sure it should work with Server Sent Events if WebSockets don't work though...? – thab Sep 23 '16 at 09:45
  • Actually, I am not getting. First I want to know that shall we test signalr in localhost or have to deploy on IIS ? Second if it's starting connection with signalr then why this error. – NeilSah Sep 23 '16 at 10:03
  • Yes Signalr works on localhost with vs2015 - I'm doing that right now. Actually I noticed you've just said that it gets to `alert("connection started")` - which implies to me it is working. Why do you think it's not working? or is it just the error? – thab Sep 23 '16 at 10:20
  • Are you using IIS or IIS Express? If you are using IIS then make sure that websockets are enabled - AFAIR they are disabled by default. – Pawel Sep 23 '16 at 16:28
  • 1
    Possible duplicate of [SignalR: Error during WebSocket handshake: Unexpected response code: 400](http://stackoverflow.com/questions/23130152/signalr-error-during-websocket-handshake-unexpected-response-code-400) – Saurabh Srivastava Oct 01 '16 at 04:34

0 Answers0