Example #1
0
class WebSocketHandler(BaseHandler):
    """ We're assuming a bit about the websocket API that will be used """
    
    def __init__(self, websocket, broker):
        self.websocket = websocket
        self.parser = StreamParser()
        super(WebSocketHandler, self).__init__(broker)
    
    def _recv(self):
        message = self.websocket.receive()
        self.parser.feed(str(message))
        return self.parser.getFrame()
    
    def _send(self, command, headers, body=None):
        self.websocket.send(StreamFrame(command, headers, body).pack())
    
    def _close(self):
        self.websocket.close()
Example #2
0
 def __init__(self, websocket, broker):
     self.websocket = websocket
     self.parser = StreamParser()
     super(WebSocketHandler, self).__init__(broker)