title: How to use http websocket on Mongoose embedded web server with SSL?
body: <p>I'm trying to use Http WebSocket on Mongoose embedded web server with SSL.</p>
  
  <p>And I tried this mongoose example called "simplest_web_server_ssl".
  But when I executed the program, it printed out this message below.</p>
  
  <p>"Failed to create listener: Invalid SSL cert"</p>
  
  <p>I think it's because the program doesn't know where the "server.pem" file is.
  I put these "server.pem" and "server.key" files from the example folder into a "release" folder where the .exe file is created and runs.</p>
  
  <p>Actually I'm quite new to Mongoose and SSL.</p>
  
  <p>Please anybody could help me? </p>
  
  <p>Thanks, regards.</p>
  
  <pre><code>/*
  * Copyright (c) 2016 Cesanta Software Limited
  * All rights reserved
  */
  
  /*
  * This example starts an SSL web server on https://localhost:8443/
  *
  * Please note that the certificate used is a self-signed one and will not be
  * recognised as valid. You should expect an SSL error and will need to
  * explicitly allow the browser to proceed.
  */
  
  #include "mongoose.h"
  
  static const char *s_http_port = "8443";
  static const char *s_ssl_cert = "server.pem";
  static const char *s_ssl_key = "server.key";
  static struct mg_serve_http_opts s_http_server_opts;
  
  static void ev_handler(struct mg_connection *nc, int ev, void *p) {
      if (ev == MG_EV_HTTP_REQUEST) {
          mg_serve_http(nc, (struct http_message *) p, s_http_server_opts);
      }
  }
  
  int main(void) {
      struct mg_mgr mgr;
      struct mg_connection *nc;
      struct mg_bind_opts bind_opts;
      const char *err;
  
      mg_mgr_init(&amp;mgr, NULL);
      memset(&amp;bind_opts, 0, sizeof(bind_opts));
      bind_opts.ssl_cert = s_ssl_cert;
      bind_opts.ssl_key = s_ssl_key;
      bind_opts.error_string = &amp;err;
  
      printf("Starting SSL server on port %s, cert from %s, key from %s\n",
          s_http_port, bind_opts.ssl_cert, bind_opts.ssl_key);
      nc = mg_bind_opt(&amp;mgr, s_http_port, ev_handler, bind_opts);
      if (nc == NULL) {
          printf("Failed to create listener: %s\n", err);
          return 1;
      }
  
      // Set up HTTP server parameters
      mg_set_protocol_http_websocket(nc);
      s_http_server_opts.document_root = ".";  // Serve current directory
      s_http_server_opts.enable_directory_listing = "yes";
  
      for (;;) {
          mg_mgr_poll(&amp;mgr, 1000);
      }
      mg_mgr_free(&amp;mgr);
  
      return 0;
  }
  </code></pre>