Changes between Version 19 and Version 20 of ProposedWikiStart
- Timestamp:
- 03/26/2012 03:03:43 PM (14 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ProposedWikiStart
v19 v20 122 122 <li class="active"><a href="#echoserver">Echo Server</a></li> 123 123 <li><a href="#webserver">Web server</a></li> 124 <li><a href="# chatserver">Chat server</a></li>124 <li><a href="#pubsubserver">Publish/subscribe</a></li> 125 125 </ul> 126 126 }}} … … 180 180 181 181 {{{ 182 #!div class="tab-pane" id=" chatserver"183 Here's what a simple chat server might look like:182 #!div class="tab-pane" id="pubsubserver" 183 Here's a simple publish/subscribe server, where clients see all messages posted by other clients: 184 184 185 185 {{{ … … 188 188 from twisted.protocols import basic 189 189 190 class ChatProtocol(basic.LineReceiver):190 class PubProtocol(basic.LineReceiver): 191 191 delimiter = "\n" 192 192 … … 207 207 208 208 209 class ChatFactory(protocol.Factory):209 class PubFactory(protocol.Factory): 210 210 def __init__(self): 211 211 self.clients = set() 212 212 213 213 def buildProtocol(self, addr): 214 return ChatProtocol(self)214 return PubProtocol(self) 215 215 216 216 217 217 if __name__ == '__main__': 218 reactor.listenTCP(1025, ChatFactory())218 reactor.listenTCP(1025, PubFactory()) 219 219 reactor.run() 220 220 }}}
