title: uWebSockets (C++): secure wss server
body: <p>I am using uWebSockets in C++ to host a WebSocket server. However,  I need it to be a secure <code>wss</code> server instead of simply a <code>ws</code> server.</p>
  
  <p>I have tried this code:</p>
  
  <pre><code>uS::TLS::Context tls = uS::TLS::createContext ("./cert.perm", "./key.perm", "passphrase");
  
  if (h.listen (9002, tls)) {
      cout &lt;&lt; "Game server listening on port 9002" &lt;&lt; endl;
      h.run();
  }
  </code></pre>
  
  <p>I am using this shell command to generate the certificate and key:</p>
  
  <pre><code>openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 30
  </code></pre>
  
  <p>I then tried connecting to my remote server using <code>wss://address</code> instead of the usual <code>ws://address</code>, however, it cannot connect.</p>
  
  <p>Any ideas why? Thanks</p>
  
  <p><strong>UPDATE #1</strong></p>
  
  <p>The <code>tls</code> variable seems to be actually <code>NULL</code>, so it looks like the certificate part isn't working.</p>
  
  <p><strong>UPDATE #2</strong></p>
  
  <p>I got the file extensions wrong in the code, they're meant to be <code>pem</code> instead of <code>perm</code>. However, the server will now not establish a connection on both <code>wss</code> and <code>ws</code>.</p>
  
  <p><strong>UPDATE #3</strong></p>
  
  <p>After fixing the issue mentioned above, the <code>tls</code> variable is now <code>1</code> instead of <code>0</code> (which I assumed was <code>NULL</code>).</p>