Skip to content

Instantly share code, notes, and snippets.

@abhigenie92
Created April 6, 2016 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhigenie92/656364cdb9c7dd3cf601bdb69d763d10 to your computer and use it in GitHub Desktop.
Save abhigenie92/656364cdb9c7dd3cf601bdb69d763d10 to your computer and use it in GitHub Desktop.
from twisted.internet.protocol import Protocol, Factory
class StrokeEcho(Protocol):
def __init__(self, factory):
self.factory = factory
def connectionMade(self):
print self
self.factory.echoers.append(self)
def dataReceived(self, data):
print "Data:",data
print "Connected clients:",self.factory.echoers
for echoer in self.factory.echoers:
if not self:
print "sent data to:",echoer
echoer.transport.write(data)
def connectionLost(self, reason):
self.factory.echoers.remove(self)
class StrokeEchoFactory(Factory):
def __init__(self):
self.echoers = []
def buildProtocol(self, addr):
return StrokeEcho(self)
2016-04-06 20:53:58+0530 [-] <stroke_protocol.StrokeEcho instance at 0x0000000004FD32C8>
2016-04-06 20:54:15+0530 [-] <stroke_protocol.StrokeEcho instance at 0x000000000504CFC8>
2016-04-06 20:54:19+0530 [-] Data: [{"color": "#ffffff", "width": 2, "points": [298.0, 383.0, 298.0, 382.00000000000006, 298.0, 367.0, 298.0, 355.0, 298.0, 330.0, 298.0, 307.0, 298.0, 297.0, 298.0, 280.00000000000006, 298.0, 270.0, 298.0, 256.0, 300.0, 251.0, 300.0, 245.0, 300.0, 242.00000000000003, 300.0, 238.99999999999997, 300.0, 237.0, 300.0, 235.99999999999997, 301.0, 235.99999999999997, 301.0, 235.00000000000003]}]
2016-04-06 20:54:19+0530 [-] Connected clients: [<stroke_protocol.StrokeEcho instance at 0x0000000004FD32C8>, <stroke_protocol.StrokeEcho instance at 0x000000000504CFC8>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment