Mac OSX環境でソケットプログラミングを使用してサンプルを作成するためのチュートリアルhttp://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-serverをフォローしています。
私はreactor.listenTCP(80、factory)のpost80を使用して書いています。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を使用するにはどうすればよいか知りたかっただけです。