Exemplo n.º 1
0
class StompHandler(BaseHandler):
    """ We're assuming a bit about the websocket API that will be used """
    
    def __init__(self, websocket, broker):
        self.websocket = websocket
        self.parser = StompParser()
        super(StompHandler, 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(StompFrame(command, headers, body).pack())
    
    def _close(self):
        self.websocket.close()
Exemplo n.º 2
0
class StompHandler(BaseHandler):
    def __init__(self, socket, broker):
        self.socket = socket
        self.parser = StompParser()
        super(StreamHandler, self).__init__(broker)
    
    def _recv(self):
        self.parser.feed(self.socket.recv(1024))
        return self.parser.getFrame()
    
    def _send(self, command, headers, body=None):
        self.socket.sendall(StompFrame(command, headers, body).pack())
    
    def _close(self):
        try:
            self.socket.shutdown(socket.SHUT_RDWR)
            self.socket.close()
        except:
            pass