python - Send data between specific users in socket based app -
this question has reply here:
twisted - sending info selected clients 1 replyi have 2 kinds of user in app, let's , b user. have info base of operations one-to-many relationship between , b, can have multiple b's , b 1 a.
i need send info b's , b a.
i'm next raywenderlich's socket based app , server tuturial http://www.raywenderlich.com/3932/, tutorial allows user connect server , send info other users conected, chat room. protocol created identify user: iam:username
how can specific send info users in relationship, instead of conected user shown in tutorial?
the tutorial create server using python , twisted, here code used:
from twisted.internet.protocol import protocol, mill twisted.internet import reactor class iphonechat(protocol): def connectionmade(self): #self.transport.write("""connected""") self.factory.clients.append(self) print "clients ", self.factory.clients def connectionlost(self, reason): self.factory.clients.remove(self) def datareceived(self, data): #print "data ", info = 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 c in self.factory.clients: c.message(msg) def message(self, message): self.transport.write(message + '\n') mill = factory() factory.protocol = iphonechat factory.clients = [] reactor.listentcp(80, factory) print "iphone chat server started" reactor.run()
i see code:
for c in self.factory.clients: c.message(msg)
you should customize message object including destination. in server code, send message right one.
python ios sockets network-programming twisted
No comments:
Post a Comment