<s> from twisted . internet import reactor , protocol , endpoints <EOL> from twisted . protocols import basic <EOL> class PubProtocol ( basic . LineReceiver ) : <EOL> def __init__ ( self , factory ) : <EOL> self . factory = factory <EOL> def connectionMade ( self ) : <EOL> self . factory . clients . add ( self ) <EOL> def connectionLost ( self , reason ) : <EOL> self . factory . clients . remove ( self ) <EOL> def lineReceived ( self , line ) : <EOL> for c in self . factory . clients : <EOL> c . sendLine ( "<STR_LIT>" . format ( self . transport . getHost ( ) , line ) ) <EOL> class PubFactory ( protocol . Factory ) : <EOL> def __init__ ( self ) : <EOL> self . clients = set ( ) <EOL> def buildProtocol ( self , addr ) : <EOL> return PubProtocol ( self ) <EOL> endpoints . serverFromString ( reactor , "<STR_LIT>" ) . listen ( PubFactory ( ) ) <EOL> reactor . run ( ) </s>
