python - Twisted with multiple ports, protocols, and reactors -



python - Twisted with multiple ports, protocols, and reactors -

will twisted back upwards listening on multiple ports, different 'handlers' (different set of callbacks each port) @ same time? essentially, want process host 2 servers in 1 process, each performing different function. need utilize 2 reactors this?

yes, instance, modifying quote server example add together sec instance listening on different port different quote:

from twisted.internet.protocol import factory, protocol twisted.internet.endpoints import tcp4serverendpoint twisted.internet import reactor class qotd(protocol): def connectionmade(self): # self.factory set factory's default buildprotocol: self.transport.write(self.factory.quote + '\r\n') self.transport.loseconnection() class qotdfactory(factory): # used default buildprotocol create new protocols: protocol = qotd def __init__(self, quote=none): self.quote = quote or 'an apple day keeps doc away' endpoint = tcp4serverendpoint(reactor, 8007) endpoint.listen(qotdfactory("configurable quote")) endpoint2 = tcp4serverendpoint(reactor, 8008) endpoint2.listen(qotdfactory("another configurable quote")) reactor.run()

output:

$ nc localhost 8007 configurable quote $ nc localhost 8008 configurable quote

python network-programming

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -