Tôi đang làm theo hướng dẫn http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server để tạo mẫu bằng cách sử dụng lập trình socket trong môi trường Mac OS X.Lò phản ứng xoắn bằng Python - địa chỉ đã sử dụng
Tôi đang viết bằng cách sử dụng bài 80 cho reactor.listenTCP (80, nhà máy). Khi tôi chạy file server.py, nhận được một lỗi:
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.
Mã nguồn như sau:
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()
Nếu tôi đang sử dụng một cổng không như 6 vv, nó đang làm việc tốt . Tôi chỉ muốn biết, làm cách nào tôi có thể sử dụng cổng 80 cho cùng một ứng dụng.
Cổng 80 là máy chủ lưu trữ cho giao thức HTTP. Kiểm tra nếu không có quá trình chạy trên cổng này. Có lẽ một số máy chủ HTTP, như apache? –