我正在学习教程 http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server用于在 Mac OS X 环境中使用套接字编程创建示例。
我正在使用 post 80 编写 reactor.listenTCP(80, factory)。 当我运行 server.py 文件时,出现错误:
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 用于同一个应用程序。
最佳答案
打开事件监视器,搜索 Python 并终止进程。您可能搞砸了一次关闭服务器。
关于Python twisted reactor - 地址已被使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14640711/