簡単 Echo Server

こんなんでどうでしょう。
シンプルシンプル。

# vim: fileencoding=utf8 sw=4 sts=4

from twisted.protocols import basic
from twisted.internet import protocol, reactor

class EchoServer(basic.LineReceiver):
    def connectionMade(self):
        self.factory.clients.append(self)

    def connectionLost(self):
        self.factory.clients.remove(self)

    def lineReceived(self, line):
        for client in self.factory.clients:
            client.message(line)

    def message(self, message):
        self.transport.write(message + '\n')

factory = protocol.ServerFactory()
factory.protocol = EchoServer
factory.clients = []

reactor.listenTCP(12345, factory)
reactor.run()