我正在按照教程http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server在 Mac OS X 环境中使用套接字编程创建示例。
我正在为 reactor.listenTCP(80, factory) 使用 post 80 编写。当我运行 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 用于同一应用程序。