Sending message from one server to another in Twisted

Posted by Casey Patton on Stack Overflow See other posts from Stack Overflow or by Casey Patton
Published on 2011-11-21T09:46:40Z Indexed on 2011/11/21 9:50 UTC
Read the original article Hit count: 216

Filed under:
|

I've implemented my servers in the following way:

def makeServer(application, port):
    factory = protocol.ServerFactory()
    factory.protocol = MyChat
    factory.clients = []
    internet.TCPServer(port, factory).setServiceParent(application)

application = service.Application("chatserver")
server1 = makeServer(application, port=1025)
server2 = makeServer(application, port=1026)
server3 = makeServer(application, port=1027)

Note that MyChat is an event handling class that has a "receiveMessage" action:

def lineReceived(self, line):
    print "received", repr(line)
    for c in self.factory.clients:
       c.transport.write(message + '\n')

I want server1 to be able to pass messages to server2. Rather, I want server1 to be treated as a client of server2. If server1 receives the message "hi" then I want it to send that same exact message to server2.

How can I accomplish this?

© Stack Overflow or respective owner

Related posts about python

Related posts about twisted