Hello.

There is a webscoket self-written server in php, everything works fine in the http ws bundle.

But through the self-signed certificate the error failed: Error in connection establishment: net :: ERR_CONNECTION_RESET.

The stream_socket_accept ($ socket) function returns false. Server.php code

$context = stream_context_create(); stream_context_set_option($context, 'ssl', 'local_cert', '/etc/ssl/private/server.key'); stream_context_set_option($context, 'ssl', 'local_cert', '/etc/ssl/certs/server.pem'); stream_context_set_option($context, 'ssl', 'passphrase',''); stream_context_set_option($context, 'ssl', 'allow_self_signe', true); $socket = stream_socket_server("ssl://192.168.43.168:8078",$errno,$errstr,STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context); if (!$socket) { die("$errstr ($errno)\n"); } $read[] = $socket; $db = new dbquery(); global $jsdata; $authClient = array(); $write = $except = null; while(true) { $read[] = $socket; stream_select($read, $write, $except,1, 0); if (in_array($socket, $read)) { try { $newSocket = stream_socket_accept($socket); } catch (Exception $e) { } 

client.js

 var uri ="wss://192.168.43.168:8078?id="+$('#iduser').val(); var socket = new WebSocket(uri); 
  • Does the browser trust this certificate? - Pavel Mayorov
  • No trusts, certificate certificate chain (net :: ERR_CERT_DATE_INVALID - user3035145
  • Well, that's why false returns that the connection was dropped during the installation. - Pavel Mayorov
  • failed: Error in connection establishment: net :: ERR_SSL_VERSION_OR_CIPHER_MISMATCH What kind of error is this in the know? - user3035145
  • @PavelMayorov I'm not an expert on networking, but as far as I understand, connection reset means failure even at the level of tcp connection - etki

2 answers 2

You have a typo in the allow_self_signed option:

  stream_context_set_option($context, 'ssl', 'allow_self_signe', true); 

    Connected a certificate signed by a certificate authority. It all worked. You just need to create a pem server key

     cat server.crt server.key > server.pem 

    Well, do not forget to indicate the domain name everywhere

     wss:\\domain-name:8078