"""The most basic chat protocol possible. run me with twistd -y chatserver.py, and then connect with multiple telnet clients to port 1025 """ from twisted.protocols.basic import LineReceiver class MyChat(basic.LineReceiver): def __init__(self): self.quote = 'An apple a day keeps the doctor away' def connectionMade(self): print "Got new client!" self.factory.clients.append(self) def connectionLost(self, reason): print "Lost a client!" self.factory.clients.remove(self) def lineReceived(self, line): print "received", repr(line) for c in self.factory.clients: c.message("respuesta server: " + line) def message(self, message): self.sendLine(message + '\n') from twisted.internet import protocol, reactor from twisted.application import service, internet factory = protocol.ServerFactory() factory.protocol = MyChat factory.clients = [] reactor.listenTCP(8007, factory) reactor.run() #application = service.Application("chatserver") #internet.TCPServer(1025, factory).setServiceParent(application)