Python twisted reactor - address already in use

旧时模样 提交于 2019-12-05 02:32:17

Open Activity Monitor, search for Python and kill the process. You probably messed up with closing a server once.

I encountered this issue too, actually, just now.

Here is what I did:

MacBook-Air:Desktop user$ sudo lsof -i:80
COMMAND  PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Python  1276 root    3u  IPv4 ******      0t0  TCP *:http (LISTEN)
MacBook-Air:Desktop user$ sudo kill 1276
MacBook-Air:Desktop user$ sudo python server.py 
Iphone Chat server started

Then everything goes well.

For me the issue was that apache was already listening on port 80. Seems like a lot of people google through this post and other ones with this issue but I don't see this particular answer offered. It was what worked for me so I thought that I would add to it in case it helps: Running Mac/Mavericks but the issue would occur on any other system where Apache runs by default ... or one might forget it's running.

Did

sudo lsof -i TCP:80 | grep LISTEN

Got

httpd      20 root    4u  IPv6 0x1d12a12e12345b12      0t0  TCP *:http (LISTEN)
httpd     109 _www    4u  IPv6 0x1d12a12e12345b12      0t0  TCP *:http (LISTEN)
httpd     437 _www    4u  IPv6 0x1d12a12e12345b12      0t0  TCP *:http (LISTEN)
httpd     438 _www    4u  IPv6 0x1d12a12e12345b12      0t0  TCP *:http (LISTEN)
httpd     439 _www    4u  IPv6 0x1d12a12e12345b12      0t0  TCP *:http (LISTEN)

did

sudo apachectl stop

And the server worked just fine on port 80 after that.

You can't listen port if another application already bound socket to this port. For example read socket.bind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!