내 앱에는 두 가지 종류의 사용자가 있습니다. A와 B 사용자를 예로 들어 보겠습니다. 나는 A와 B 사이에 일대 다 관계가있는 데이터베이스를 가지고 있으므로 A는 복수의 B와 B를 가질 수있다.소켓 기반 앱의 특정 사용자간에 데이터 전송
데이터를 A에서 B로, B에서 B로 보내야한다. A.
이 튜토리얼에서는 Raywenderlich의 소켓 기반 앱 및 서버 튜토리얼 http://www.raywenderlich.com/3932/을 따르고 있습니다.이 튜토리얼을 통해 사용자는 서버를 연결하고 다른 모든 사용자 (대화방)에게 데이터를 보낼 수 있습니다. iam : username
자습서에 표시된 것처럼 연결 한 사용자 대신 관계의 사용자에게만 특정 데이터를 보낼 수 있습니까?
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()
좋은 접근 방법일까요? 그것은 일을 할 것이지만, 나는 그것을 위해 연결된 모든 클라이언트에 도달해야 할 것이다. 연결된 모든 사용자를 검색하지 않고 특정 사용자에게 직접 데이터를 보내려면 어떤 종류의 P2P 응용 프로그램이 있습니까? – douglasd3