How can I do a multithreading twisted python -


i have question bothers me long time, i'm working on daemon operating requests outside. server-client. in project, i'm using twisted python framework, , successful build non-multithreading server, works! now, need serve several customers @ once. don't know how can in twisted framework. tried know...

please me :|

class server(protocol.protocol, protocol.factory):  def buildprotocol(self, addr):                                    if addr.host in iplist:         log.msg("connected ip: " + addr.host)         return self     return none  def datareceived(self, data):     reactor.callfromthread(self.actioncreator(data))  def actioncreator(self, data):     jsondata = json.loads(data)     if not jsondata["action"]:         log.msg("incorrect data ip: " + self.transport.getpeer().host + " data: " + data)         self.transport.write(json.dumps({'response' : '300'}))     elif jsondata["action"] == 'echo':         log.msg("doing ask ip: " + self.transport.getpeer().host)         self.transport.write(json.dumps({'response' : '400', 'data' : {'status' : 'online'}}))     elif jsondata["action"] == 'wget':          log.msg("downloading file... user - " + jsondata["user"])         os.system("wget -q http://****************")         self.transport.write(json.dumps({'response' : '400', 'data' : {'status' : 'downloaded'}}))     else:         log.msg("incorrect data ip: " + self.transport.getpeer().host + " data: " + data)         self.transport.write(json.dumps({'response' : '300'}))   if __name__ == '__main__':     try:         log.msg("running server...")         context = ssl.defaultopensslcontextfactory(certificate + "/server.key", certificate + "/server.crt")         log.msg("initiating secure ssl connection...")         reactor.listenssl(config.getint(general, 'port'), server(), context)         log.msg("waiting connections...")          reactor.run()       except keyboardinterrupt:         sys.exit() 

your server handles concurrent clients default - without threads - property of programming model followed twisted.

i don't see in example code invalidates - if remove (broken) attempt use threads server shouldn't have problem servicing more 1 client.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -