- commit
- a4a62ba4640dee020fd1450e2e43270df2636cc1
- parent
- d4ebd7df17651d62df1b955cee134ac1715aba69
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2014-10-05 09:21
move ServerProtocolFactory to protocol
Diffstat
| M | laneya/protocol.py | 26 | ++++++++++++++++++++++++-- |
| M | laneya/server.py | 11 | +---------- |
2 files changed, 25 insertions, 12 deletions
diff --git a/laneya/protocol.py b/laneya/protocol.py
@@ -66,6 +66,7 @@ import json 66 66 67 67 from twisted.python import log 68 68 from twisted.protocols.basic import NetstringReceiver -1 69 from twisted.internet.protocol import Factory 69 70 from twisted.internet import reactor 70 71 71 72 import deferred as q @@ -180,9 +181,24 @@ class ServerProtocol(BaseProtocol): 180 181 self.sendJSON(data) 181 182 182 183 def broadcastUpdate(self, action, **kwargs): -1 184 """See :py:meth:`ServerProtocolFactory.broadcastUpdate`.""" -1 185 self.factory.broadcastUpdate(action, **kwargs) -1 186 -1 187 -1 188 class ServerProtocolFactory(Factory): -1 189 """Factory for :py:class:`ServerProtocol`.""" -1 190 -1 191 def __init__(self, protocol): -1 192 self.protocol = protocol -1 193 self.connections = [] -1 194 -1 195 def buildProtocol(self, addr): -1 196 return self.protocol(self) -1 197 -1 198 def broadcastUpdate(self, action, **kwargs): 183 199 """Broadcast an update to all connected clients.""" 184 200185 -1 for connection in self.factory.connections:-1 201 for connection in self.connections: 186 202 connection._sendUpdate(action, **kwargs) 187 203 188 204 @@ -248,4 +264,10 @@ class ClientProtocol(BaseProtocol): 248 264 return d.promise 249 265 250 266251 -1 __all__ = ['InvalidError', 'IllegalError', 'ServerProtocol', 'ClientProtocol']-1 267 __all__ = [ -1 268 'InvalidError', -1 269 'IllegalError', -1 270 'ServerProtocol', -1 271 'ServerProtocolFactory', -1 272 'ClientProtocol', -1 273 ]
diff --git a/laneya/server.py b/laneya/server.py
@@ -1,7 +1,6 @@ 1 1 import sys 2 2 3 3 from twisted.python import log4 -1 from twisted.internet.protocol import Factory5 4 from twisted.internet.endpoints import TCP4ServerEndpoint 6 5 from twisted.internet import reactor 7 6 @@ -18,18 +17,10 @@ class ServerProtocol(protocol.ServerProtocol): 18 17 return {} 19 18 20 1921 -1 class ServerProtocolFactory(Factory):22 -1 def __init__(self):23 -1 self.connections = []24 -125 -1 def buildProtocol(self, addr):26 -1 return ServerProtocol(self)27 -128 -129 20 def main(): 30 21 log.startLogging(sys.stdout) 31 22 endpoint = TCP4ServerEndpoint(reactor, 5001)32 -1 endpoint.listen(ServerProtocolFactory())-1 23 endpoint.listen(protocol.ServerProtocolFactory(ServerProtocol)) 33 24 reactor.run() 34 25 35 26