Changes between Version 214 and Version 215 of WikiStart


Ignore:
Timestamp:
04/12/2012 12:07:38 AM (7 years ago)
Author:
Glyph
Comment:

Simplify pubsub protocol implementation; use sendLine rather than a custom delimiter, don't bother skipping 'self'. (Also, new-style format but please feel free to revert that if you don't think it's nicer.)

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart

    v214 v215  
    189189
    190190class PubProtocol(basic.LineReceiver):
    191     delimiter = "\n"
    192 
    193191    def __init__(self, factory):
    194192        self.factory = factory
     
    201199
    202200    def lineReceived(self, line):
    203         message = "<%s> %s\n" % (self.transport.getHost(), line)
    204201        for c in self.factory.clients:
    205             if c != self:
    206                 c.transport.write(message)
    207 
     202            c.sendLine("<{}> {}".format(self.transport.getHost(), line))
    208203
    209204class PubFactory(protocol.Factory):
     
    214209        return PubProtocol(self)
    215210
    216 
    217211if __name__ == '__main__':
    218212    reactor.listenTCP(1025, PubFactory())
    219213    reactor.run()
    220214}}}
     215
     216You can test this out by opening two terminals and doing 'telnet localhost 1025' in each, then typing things.
    221217
    222218}}}