title: WebSocket connection to 'ws://localhost:52312/' failed: Error during WebSocket handshake: Unexpected response code: 200
body: <p>I am trying to implement a simple HTML5 WebSocket, But the connection is simply not getting established &amp; I am getting below error as WebSocket object is created</p>
  
  <blockquote>
    <p>WebSocket connection to 'ws://localhost:52312/' failed: Error during WebSocket handshake: Unexpected response code: 200</p>
  </blockquote>
  
  <p>Below is the code</p>
  
  <pre><code> document.addEventListener("DOMContentLoaded", function (event) {
          function runHub() {
              if ("WebSocket" in window) {
  
                  console.log('WebSocket is supported by your browser.');
  
                  //var serviceUrl = 'ws://localhost:52312/';
                  var serviceUrl = 'ws://localhost:52312/home/GetNotificationCount';
  
                  var protocol = 'Chat-1.0';
                  var socket = new WebSocket(serviceUrl);
  
                  socket.onopen = function () {
                      console.log('Connection Established!');
                  };
  
                  socket.onclose = function (error) {
                      console.log('Connection Closed!');
                      console.log('Error Occured: ' + JSON.stringify(error));
                  };
  
                  socket.onerror = function (error) {
                      console.log('Error Occured: ' + JSON.stringify(error));
                  };
  
                  socket.onmessage = function (e) {
                      if (typeof e.data === "string") {
                          console.log('String message received: ' + e.data);
                      }
                      else if (e.data instanceof ArrayBuffer) {
                          console.log('ArrayBuffer received: ' + e.data);
                      }
                      else if (e.data instanceof Blob) {
                          console.log('Blob received: ' + e.data);
                      }
                  };
  
  
                  if (!socket.readyState === WebSocket.CLOSED) {
                      socket.send($('#notificationCount').text);
                      //socket.close();
  
                  }
  
              }
          }
  
          var run = setInterval(function () {
              runHub();
          }, 10000)
      });
  </code></pre>
  
  <p>Does anyone have any idea about this?</p>