Skip to content

Instantly share code, notes, and snippets.

@thomasballinger
Created November 20, 2013 01:00
Show Gist options
  • Select an option

  • Save thomasballinger/7555675 to your computer and use it in GitHub Desktop.

Select an option

Save thomasballinger/7555675 to your computer and use it in GitHub Desktop.
txws, websockets, classmethods vs staticmethods,
from twisted.python import log
from sys import stdout
log.startLogging(stdout)
from twisted.internet.protocol import Protocol, Factory
VisualizerClient.update_everybody()
class VisualizerClient(object):
clients = []
def __init__(self, wsp):
self.wsp = wsp
wsp.visualizer = self
self.clients.append()
def die(self):
self.clients.remove(self)
@classmethod
def update_everybody(cls):
for client in cls.clients:
client.update()
@staticmethod #THIS ONE WON'T WORK
def update_everybody_hardcoded():
for client in VisualizerClient(object):
client.update()
def update(self):
self.wsp.transport.write(s)
class Prettiness(VisualizerClient):
clients = []
Prettiness.update_everybody()
class EchoProtocol(Protocol):
def dataReceived(self, data):
self.transport.write(data)
def loseConnection(self):
self.visualizer.die()
class EchoFactory(Factory):
protocol = EchoProtocol
def buildProtocol(self):
p = self.procotol()
VisualizerClient(p)
return p
from txws import WebSocketFactory
from twisted.application.strports import listen
port = listen("tcp:5600", WebSocketFactory(EchoFactory()))
from twisted.internet import reactor
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment