title: web socket not working with SSL and WSS in javascript
body: <p>I have implemented web socket using below code,</p>
  
  <pre><code>try {
          console.log('wss://' + hostname + ':' + port + endpoint);
          webSocket = new WebSocket(webSocketURL);
          webSocket.onmessage = function (event) {
              //console.log('send message successfully.');
              var obj = JSON.parse(event.data);
              append_data(obj, market_pair);
          };
      } catch (exception) {
          console.log('Exception handle!');
          console.error(exception);
      }
  </code></pre>
  
  <p>My page is https supported so I am using wss protocol. but issue is it gives me error that "Firefox can’t establish a connection to the server at wss://domainname.com:4008/order.php"
  if I will load the page using simple http and use ws in websocket then it is working fine but with wss it shows above error. same way in google chrome it will also not able to connect.
  My ssl certificate is installed correctly in server and my hosting and domain provided in godaddy and they told me that certificate is installed correctly.</p>
  
  <p>I am running server side socket in php and it is working fine just now able to connect to that socket port using wss://</p>
  
  <p>I have found that I am not able to do handshak using my php code because my php file is running in background and the content I am getting by socket read is encrypted.</p>
  
  <pre><code>function doHandshake($received_header, $client_socket_resource, $host_name, $port) {
      echo $received_header;
      $headers = array();
      $lines = preg_split("/\r\n/", $received_header);
      foreach ($lines as $line) {
          $line = chop($line);
          if (preg_match('/\A(\S+): (.*)\z/', $line, $matches)) {
              $headers[$matches[1]] = $matches[2];
          }
      }
  
      $secKey = $headers['Sec-WebSocket-Key'];
      echo $headers['Sec-WebSocket-Key']; 
      $secAccept = base64_encode(pack('H*', sha1($secKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')));
      //$secAccept = base64_encode(sha1($secKey . '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'));
      $buffer = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" .
              "Upgrade: websocket\r\n" .
              "Connection: Upgrade\r\n" .
              "WebSocket-Origin: $host_name\r\n" .
              "WebSocket-Location: wss://$host_name:$port/websocket/btc_boon_pair.php\r\n" .
              "Sec-WebSocket-Accept:$secAccept\r\n\r\n";
      socket_write($client_socket_resource, $buffer, strlen($buffer));
  }
  </code></pre>
  
  <p>this is my handshak function $headers['Sec-WebSocket-Key'] is undefined because $received_header is encrypted. </p>
  
  <p>can anyone suggest the solution of this issue? I have to run php file as daemon and want to connect using wss protocol.</p>