title: Firefox can’t establish a connection to the server at ws://localhost:8080/
body: <p>I have two files one is <code>test.html</code> which is:</p>
  <pre><code>&lt;script src=&quot;js/jquery-2.1.4.min.js&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    
  $(function () {
    // if user is running mozilla then use it's built-in WebSocket
    window.WebSocket = window.WebSocket || window.MozWebSocket;
  
    var connection = new WebSocket('ws://localhost:8080/');
  
    connection.onopen = function () {
      // connection is opened and ready to use
      alert('connection Open');
    };
  
    connection.onerror = function (error) {
      // an error occurred when sending/receiving data
      alert('Error');
    };
  
    connection.onmessage = function (message) {
      alert('Message');
      
    };
  });
  
  &lt;/script&gt;
  </code></pre>
  <p>And one nodejs file which is</p>
  <pre><code>var WebSocketServer = require('websocket').server;
  var http = require('http');
   
  var server = http.createServer(function(request, response) {
      console.log((new Date()) + ' Received request for ' + request.url);
      response.writeHead(404);
      response.end();
  });
  server.listen(8080, function() {
      console.log((new Date()) + ' Server is listening on port 8080');
  });
  
  
  wsServer = new WebSocketServer({
      httpServer: server,
      
      autoAcceptConnections: false
  });
  function originIsAllowed(origin) {
   return true;
  }
   
  wsServer.on('request', function(request) {
      if (!originIsAllowed(request.origin)) {
        request.reject();
        console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
        return;
      }
      
      var connection = request.accept('echo-protocol', request.origin);
      console.log((new Date()) + ' Connection accepted.');
      connection.on('message', function(message) {
          console.log(message);
          connection.sendBytes(message);
         
      });
      connection.on('close', function(reasonCode, description) {
          console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
      });
  });
  </code></pre>
  <p>While I am trying to connect with web-socket  with my HTML file its give me an error which is</p>
  <pre class="lang-none prettyprint-override"><code>Firefox can’t establish a connection to the server at ws://localhost:8080/
  </code></pre>