Ejemplo n.º 1
0
        if self.isOpen():
            self.sendClose(protocol.WebSocketProtocol.CLOSE_STATUS_CODE_NORMAL)
        else:
            raise TransportLost()

    def abort(self):
        """
        Implements :func:`autobahn.wamp.interfaces.ITransport.abort`
        """
        if self.isOpen():
            self._bailout(protocol.WebSocketProtocol.CLOSE_STATUS_CODE_GOING_AWAY)
        else:
            raise TransportLost()


ITransport.register(WampWebSocketProtocol)


def parseSubprotocolIdentifier(subprotocol):
    try:
        s = subprotocol.split(u'.')
        if s[0] != u'wamp':
            raise Exception(u'WAMP WebSocket subprotocol identifier must start with "wamp", not "{}"'.format(s[0]))
        version = int(s[1])
        serializerId = u'.'.join(s[2:])
        return version, serializerId
    except:
        return None, None


class WampWebSocketServerProtocol(WampWebSocketProtocol):
Ejemplo n.º 2
0
    def isOpen():
        return True

    def close(self):
        pass

    def abort(self):
        pass

    def onMessage(self, payload):
        for msg in self._serializer.unserialize(payload):
            reactor.callFromThread(self._session.onMessage, msg)


ITransport.register(WampLocalProtocol)


class AutobahnTransport(TransportBase):
    def __init__(self, protocol):
        super().__init__()
        self.protocol = protocol

    def send(self, opcode, *args):
        self.protocol.onMessage([opcode] + list(args))

    def realm_allowed(self, realm):
        return True

    def close_session(self):
        self.session_lost()