0

I have created a node server and used socket.io in my application. Since my application is running in a https, i have included the ssl certificate and key when creating the server. But when i start the node server and check the client side application it gives the error net::ERR_CONNECTION_REFUSED in the console. It will be great if someone can help me out with this. Thanks.

Below is my server side and client side codes,

Server side server.js file

var https = require('https');
var express = require('express');
var app = express();
var fs = require('fs');  

var options = {
    key: fs.readFileSync('key.pem'),
    cert: fs.readFileSync('cert.pem')
};

var server = https.createServer(options, app);
var io = require('socket.io')(server);
server.listen(8000);

client side js files inclution

<script src="https://myhost.com:8000/socket.io/socket.io.js">   </script>
<script>
  var socket = io('https://myhost.com:8000');
</script> 

Error comes in the console

  • maybe - http://stackoverflow.com/questions/6599470/node-js-socket-io-with-ssl will help ... even though the accepted answer seems to be disputed – Jaromanda X Jan 27 '17 at 04:46
  • @JaromandaX Thanks, but in my case in server side, node server starts with no issues. When i load the socket.io.js file from the client side only the error comes. – Sanjeewa Muhandiram Jan 27 '17 at 05:23
  • so `var socket = io('https://myhost.com:8000', {secure: true});` doesn't help you? – Jaromanda X Jan 27 '17 at 05:26
  • @JaromandaX no because the error comes when loading the js file. var socket = io('https://myhost.com:8000', {secure: true}); comes after loading the js file – Sanjeewa Muhandiram Jan 27 '17 at 05:31
  • oh, so your server doesn't know how to serve that file - nothing in your server code suggests it knows what to do for that request – Jaromanda X Jan 27 '17 at 05:43
  • yeah that's the issue.my server code doesn't give me any clue about that – Sanjeewa Muhandiram Jan 27 '17 at 05:54
  • clue? OK ... here's a clue ... which part of your server code do you think knows how to deal with a GET request for `/socket.io/socket.io.js` - nothing you posted suggests your server code deals with such a request – Jaromanda X Jan 27 '17 at 05:56
  • yeah i haven't included that part of code because when `var io = require('socket.io')(server);` runs it creates a `/socket.io/socket.io.js` file right ? so i should be able to include it in the client side code...sorry if i'm doing anything wrong here (i'm quite new to node.js/socket.io) – Sanjeewa Muhandiram Jan 27 '17 at 06:08

0 Answers0