2

I've got a socket application that I'm trying to make listen on port 443 (https). If I change the port (to e.g. 8080) I get no problems.

The error shown is

error raised: Error: listen EACCES

My app source code is:

var fs = require('fs');

// create the https server and listen on port
var options = {
    ca:   fs.readFileSync('ca.pem'),
    cert: fs.readFileSync('cert.pem'),
    key:  fs.readFileSync('server.key')
};

var server = require('https').createServer(options);
var portNo = 443;
var app = server.listen(portNo, function() {
  console.log((new Date()) + " Server is listening on port " + portNo);
});

// create the socket server on the port
var io = require('socket.io').listen(app);


// This callback function is called every time a socket
// tries to connect to the server
io.sockets.on('connection', function (socket) {

    console.log((new Date()) + ' Connection established.');

    // When a user send a SDP message
    // broadcast to all users in the room
    socket.on('message', function (message) {
        socket.broadcast.emit('message', message);
    });

    // When the user hangs up
    // broadcast bye signal to all users in the room
    socket.on('disconnect', function () {
        // close user connection
        console.log((new Date()) + " Peer disconnected.");
        socket.broadcast.emit('user disconnected');
    });
});

I've seen plenty of answers relating to Linux telling them to run as sudo so I tried running the node server as administrator but to no avail.

This is running on a Windows Server 2012 box.

Thanks.

rashleighp
  • 1,226
  • 1
  • 13
  • 21

2 Answers2

8

I would just like to add that if you do not have root permission level when you start your node app you will not be able to run on port 443

Squivo
  • 917
  • 1
  • 10
  • 21
  • Is there anyway to remove root protection for 443? – Sharjeel Ahmed Jun 26 '16 at 18:42
  • I am running Ubuntu 14.04 – Sharjeel Ahmed Jun 28 '16 at 10:51
  • http://stackoverflow.com/questions/413807/is-there-a-way-for-non-root-processes-to-bind-to-privileged-ports-1024-on-l --- I think this might help you out. I am using macOS so I just start up my app using .plists running as root, but if you want to run your apps without root privs then this article should at least cover the basics – Squivo Jun 28 '16 at 15:46
2

Have you verified that port 443 isn't already being used?

Go to your command line and run netstat -a and verify that :443 is not already in the list. If it is you'll need to terminate whatever process is using that port before proceeding.

Spencer Ruport
  • 34,865
  • 12
  • 85
  • 147
  • Can I not share a port with IIS (I have a site running as https on the same ip)? If not this would explain it. I didn't know this was a limitation. – rashleighp May 15 '13 at 17:54
  • 1
    You can not share a port with IIS. Processes can not share TCP ports. – Daniel May 15 '13 at 18:05
  • IIS is capable of serving multiple sites on a single port because it's all handled by the same process. When it receives the HTTP request it looks at the hostname HTTP header and uses that to determine which website to serve. Even so, this does not apply to 443 for reasons I don't completely understand but I suspect it has something to do with the way that SSL works. – Spencer Ruport May 15 '13 at 19:32