Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is websockets.py
- from twisted.protocols.basic import LineReceiver
- class HandshakeError(ValueError): pass
- transports = [] # <- so this holds the different transports
- class WebsocketsServerProtocol(LineReceiver):
- def __init__(self):
- self.__buffer = ''
- def connectionMade(self):
- self.__buffer = ''
- self.path = None
- self.headers = {}
- self.handshake = _handshake_state_machine()
- self.handshake.next()
- transports.append(self.transport) # <- append upon connection
- pass
- def connectionLost(self, reason):
- transports.remove(self.transport) # <- remove upon lost connection ( closing browser window etc. )
- # And sendMessage goes
- def sendMessage(self, data):
- for transport in transports:
- transport.write('\0%s\xff' % data)
- # And thats it :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement