다음 내용을 따르고 있습니다 : http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server 튜토리얼.iOS에서 python boolean을 토글하십시오.
나는이 물건을 멋지게 먹었고, 이것에서 총 멍청한 놈이되었다. 나는 내 인생에서, 아래에 붙여 넣은 튜토리얼에서 언급 한 'chatserver.py'문서에 파이썬 부울을 추가하는 방법을 알 수 없다. .
버튼을 추가하여 iPhone 앱에서 토글하고 서버에서 다시 알리려고 요청할뿐만 아니라 iPhone을 추가하고 싶습니다.
처럼, 버튼이 (어떻게 토글 메시지를 보내려면) 어떻게 부울의 상태가 바로이 의문에 대한
사과 무엇 서버를 요청하는 부울을 전환합니다. 여기
현재 서버입니다 (! 동네 짱 - 복잡, 여행 애호가)from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
class IphoneChat(Protocol):
def connectionMade(self):
#self.transport.write("""connected""")
self.factory.clients.append(self)
print "clients are ", self.factory.clients
def connectionLost(self, reason):
self.factory.clients.remove(self)
def dataReceived(self, data):
#print "data is ", data
a = data.split(':')
if len(a) > 1:
command = a[0]
content = a[1]
msg = ""
if command == "iam":
self.name = content
msg = self.name + " has joined"
elif command == "msg":
msg = self.name + ": " + content
print msg
for c in self.factory.clients:
c.message(msg)
def message(self, message):
self.transport.write(message + '\n')
factory = Factory()
factory.protocol = IphoneChat
factory.clients = []
reactor.listenTCP(80, factory)
print "Iphone Chat server started"
reactor.run()
각 연결마다 별도의 부울 값을 찾고 있습니까 (예 : 'iam' 명령의'name'과 같이 더 큰 방법으로 정의 된)? 또는 모든 사용자가 공유하는 각 클라이언트에 대해 하나씩 부울 값을 찾고 있습니까? – abarnert
또한이 질문의 어떤 부분은 채팅 프로토콜의 이름이 'IphoneChat'인 것을 제외하고는 IOS 또는 ObjC와 관련이 있습니까? – abarnert
@abarnert 내가하고있는 튜토리얼은 iPhone 용이라고 –