本文介绍了Python扭曲反应堆-地址已在使用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注 http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server ,用于在Mac OS X环境中使用套接字编程创建示例.

I'm following a tutorial http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server for creating a sample using socket programming in Mac OS X enviromment.

我正在使用80帖子编写reactor.listenTCP(80,factory).当我运行server.py文件时,出现错误:

I'm writing using post 80 for reactor.listenTCP(80, factory).When I run the server.py file, getting an error:

File "server.py", line 10, in <module>
    reactor.listenTCP(6, factory)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/posixbase.py", line 436, in listenTCP
    p.startListening()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/tcp.py", line 641, in startListening
    raise CannotListenError, (self.interface, self.port, le)
twisted.internet.error.CannotListenError: Couldn't listen on any:80: [Errno 48] Address already in use.

源代码如下:

from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor

class IphoneChat(Protocol):
    def connectionMade(self):
        self.factory.clients.append(self)
        print "clients are ", self.factory.clients

    def connectionLost(self, reason):
        self.factory.clients.remove(self)

factory = Factory()
factory.protocol = IphoneChat
factory.clients = []
reactor.listenTCP(80, factory)
print "Iphone Chat server started"
reactor.run()

如果我正在使用另一个端口(例如6等),则工作正常.我只是想知道,如何在同一应用程序中使用端口80.

If I'm using another port no like 6 etc, it is working fine.I just wanted to know, how can I use port 80 for the same application.

推荐答案

打开活动监视器,搜索Python并终止该进程.您可能搞砸了一次关闭服务器.

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

这篇关于Python扭曲反应堆-地址已在使用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:55