博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何解决错误:使用nodejs时监听EADDRINUSE?
阅读量:2380 次
发布时间:2019-05-10

本文共 2988 字,大约阅读时间需要 9 分钟。

本文翻译自:

If I run a server with the port 80, and I try to use i get this error: Error: listen EADDRINUSE 如果我使用端口80运行服务器,并且尝试使用收到此错误: Error: listen EADDRINUSE

Why is it problem for nodejs, if I want to do a request, while I run a server on the port 80? 在80端口上运行服务器时,如果要发出请求,为什么nodejs会出现问题? For the webbrowsers it is not a problem: I can surf on the internet, while the server is running. 对于网络浏览器而言,这不是问题:服务器运行时,我可以在Internet上冲浪。

The server is: 服务器是:

net.createServer(function (socket) {    socket.name = socket.remoteAddress + ":" + socket.remotePort;    console.log('connection request from: ' + socket.remoteAddress);    socket.destroy();  }).listen(options.port);

And the request: 并要求:

var xhr = new XMLHttpRequest();xhr.onreadystatechange = function() {    sys.puts("State: " + this.readyState);    if (this.readyState == 4) {        sys.puts("Complete.\nBody length: " + this.responseText.length);        sys.puts("Body:\n" + this.responseText);    }};xhr.open("GET", "http://mywebsite.com");xhr.send();

#1楼

参考:


#2楼

Just a head's up, Skype will sometimes listen on port 80 and therefore cause this error if you try to listen on port 80 from Node.js or any other app. 抬起头来,Skype有时会在端口80上侦听,因此,如果您尝试从Node.js或任何其他应用程序侦听端口80,则会导致此错误。

You can turn off that behaviour in Skype by accessing the options and clicking Advanced -> Connection -> Use port 80 (Untick this) 您可以通过访问选项并单击“高级”->“连接”->“使用端口80”(取消选中此选项)来在Skype中关闭该行为。

关闭Skype端口80的使用

PS After making that change, don't forget to restart Skype! PS进行更改后,请不要忘记重新启动Skype!


#3楼

Another thing that can give this error, is two HTTP servers in the same node code. 可能导致此错误的另一件事是同一节点代码中的两个HTTP服务器。 I was updating some Express 2 to Express 3 code, and had this... 我正在将一些Express 2更新为Express 3代码,并且有这个...

http.createServer(app).listen(app.get('port'), function(){              console.log('Express server listening on port ' + app.get('port')); });        // tons of shit.http.createServer(app).listen(app.get('port'), function(){              console.log('Express server listening on port ' + app.get('port')); });

And, it triggered this error. 并且,它触发了此错误。


#4楼

What really helped for me was: 对我真正的帮助是:

killall -9 node

But this will kill a system process. 但这会杀死系统进程。

With

ps ax

you can check if it worked. 您可以检查它是否有效。


#5楼

You should try killing the process that is listening on port 80. 您应该尝试终止正在侦听端口80的进程。

Killall will kill all the node apps running. Killall将杀死所有正在运行的节点应用程序。 You might not want to do that. 您可能不想这样做。 With this command you can kill only the one app that is listening on a known port. 使用此命令,您只能杀死正在已知端口上监听的一个应用程序。

If using unix try this command: 如果使用unix,请尝试以下命令:

sudo fuser -k 80/tcp

#6楼

I have the same problem too,and I simply close the terminal and open a new terminal and run 我也有同样的问题,我只需要关闭终端并打开一个新终端并运行

node server.js

again. 再次。 that works for me, some time just need to wait for a few second till it work again. 这项功能对我来说有效,有时只需要等待几秒钟,直到它再次起作用。

But this works only on a developer machine instead of a server console.. 但这仅适用于开发人员机器,而不适用于服务器控制台。

转载地址:http://ufexb.baihongyu.com/

你可能感兴趣的文章
PHP学习-面向对象
查看>>
js页面跳转整理
查看>>
在64位Win7操作系统中安装Microsoft Access Engine的解决方案
查看>>
30类CSS选择器
查看>>
微信支付的使用介绍
查看>>
PHP单例模式应用详解
查看>>
冒号课堂§5.2:数据类型
查看>>
博客搬家
查看>>
冒号课堂§6.2:平台语言
查看>>
《关于信息系统组织方式的一个提案》的评论与反评
查看>>
冒号和他的学生们(连载10)——超级范式
查看>>
冒号和他的学生们(连载9)——泛型范式
查看>>
冒号和他的学生们(连载13)——范式总结
查看>>
A Proposal on Organization of Information System
查看>>
冒号和他的学生们(连载2)——首轮提问
查看>>
正则表达式与文件格式化处理
查看>>
Java EE互联网轻量级框架整合开发
查看>>
Java语言程序设计(基础篇)
查看>>
大型网站技术架构:核心原理与案例分析
查看>>
JAVA并发编程实战
查看>>