[英]Node.js Tcp server EACCESS
Using net to create a TCP server on Node.js on a windows machine 使用net在Windows机器上的Node.js上创建TCP服务器
var net = require('net');
var host = 'localhost';
var port = '7171';
net.createServer(function(socket) {
console.log('CONNECTED - ' + socket.remoteAddress);
}).listen(host, port);
But Im getting this EACCES error even if I run the node console as admin with control shift click. 但是,即使我以Shift键单击以admin身份运行节点控制台,我仍收到此EACCES错误。
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EACCES
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1023:19)
at listen (net.js:1064:10)
at Server.listen (net.js:1132:5)
at Object.<anonymous> (E:\Xampp\htdocs\tibiajs\server.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
Since at windows I normally dont have to deal with these kind of privilegies issues I dont know what to do 由于在Windows上,我通常不必处理此类特权问题,因此我不知道该怎么办
You have your params backward: 您的参数落后了:
.listen(host, port);
should be 应该
.listen(port, host);
Also I'd probably pass the port number as a number instead of a string, but either appears to work. 另外,我可能会将端口号作为数字而不是字符串进行传递,但两者似乎都起作用。
Docs: http://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback 文件: http : //nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback
server.listen() takes a port, with optional host. server.listen()带端口,带有可选主机。 Signature is listen(port, [host], [backlog], [callback]).
签名是listen(端口,[主机],[backlog],[callback])。 I think this is what you want:
我认为这是您想要的:
var net = require('net');
var port = '7171';
net.createServer(function(socket) {
console.log('CONNECTED - ' + socket.remoteAddress);
}).listen(port);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.