【发布时间】:2013-01-16 10:27:14
【问题描述】:
我正在关注http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server 的教程,用于在 Mac OS X 环境中使用套接字编程创建示例。
我正在使用 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 用于同一个应用程序。
【问题讨论】:
-
端口 80 为 HTTP 协议保留。检查是否没有进程在此端口上运行。也许是一些 HTTP 服务器,比如 apache?
标签: python macos sockets twisted