2

我有一个套接字应用程序,我试图在端口 443 (https) 上进行监听。如果我更改端口(例如 8080),我不会遇到任何问题。

显示的错误是

error raised: Error: listen EACCES

我的应用程序源代码是:

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');
    });
});

我已经看到很多与 Linux 相关的答案告诉他们以 sudo 身份运行,所以我尝试以管理员身份运行节点服务器,但无济于事。

这是在 Windows Server 2012 机器上运行的。

谢谢。

4

2 回答 2

8

我想补充一点,如果您在启动节点应用程序时没有 root 权限级别,您将无法在端口 443 上运行

于 2014-10-09T22:36:48.307 回答
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.

于 2013-05-15T17:51:10.960 回答