node.js - WebSocket Error in connection establishment: net::ERR_CONNECTION_CLOSED -


i getting error when attempt establish wss connection server:

websocket connection 'wss://mydomain:3000/' failed: error in connection establishment: net::err_connection_closed

i have apache2 virtual host configuration setup listen requests on port 443 , 80:

<virtualhost *:80>         servername otherdomainname.co.uk         serveralias www.otherdomainname.co.uk          rewriteengine on         rewriterule ^/(.*)$ /app/$1 [l,pt]          jkmount /* worker2  </virtualhost>  <virtualhost _default_:443>         servername otherdomainname.co.uk         serveralias www.otherdomainname.co.uk          rewriteengine on         rewriterule ^/(.*)$ /app/$1 [l,pt]          sslengine on         sslcertificatefile /etc/apache2/ssl/apache.crt         sslcertificatekeyfile /etc/apache2/ssl/apache.key          <location />         sslrequiressl on         sslverifyclient optional         sslverifydepth 1         ssloptions +stdenvvars +strictrequire         </location>          jkmount /* worker2  </virtualhost> 

as can see uses jkmount pass request tomcat serves webpage correctly on both http , https.

when visit site using http protocol on port 80 websocket connection can made using ws protocol.

when visit site using https protocol on port 443 site served correctly no websocket connection made using wss.

i using "ws" node.js module provide websocket server:

var websocketserver = require('ws').server   , wss = new websocketserver({ port: 3000 }),   fs = require('fs');  wss.on('connection', function connection(ws) {   ws.on('message', function incoming(message) {     console.log('received: %s', message);      ws.send(message);   ws.send('something'); }); 

why not able successful connect websocket server using wss protocol on https?

the problem was not configure websocket server https/wss.

here secure version of insecure websocket server using "ws" node.js.

var websocketserver = require('ws').server,   fs = require('fs');   var cfg = {         ssl: true,         port: 3000,         ssl_key: '/path/to/apache.key',         ssl_cert: '/path/to/apache.crt'     };  var httpserv = ( cfg.ssl ) ? require('https') : require('http');  var app      = null;  var processrequest = function( req, res ) {      res.writehead(200);     res.end("all glory websockets!\n"); };  if ( cfg.ssl ) {      app = httpserv.createserver({          // providing server  ssl key/cert         key: fs.readfilesync( cfg.ssl_key ),         cert: fs.readfilesync( cfg.ssl_cert )      }, processrequest ).listen( cfg.port );  } else {      app = httpserv.createserver( processrequest ).listen( cfg.port ); }  var wss = new websocketserver( { server: app } );  wss.on('connection', function connection(ws) {   ws.on('message', function incoming(message) {     console.log('received: %s', message);      ws.send(message);    });    ws.send('something'); }); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -