How to use the autobahn.twisted.websocket.WebSocketClientFactory function in autobahn

To help you get started, we’ve selected a few autobahn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github modera / mcloud / mcloud / remote.py View on Github external
def connect(self):
        factory = WebSocketClientFactory("ws://%s:%s/ws/" % (self.host, self.port), debug=False)
        factory.noisy = True
        factory.protocol = MdcloudWebsocketClientProtocol
        factory.protocol.client = self

        self.onc = defer.Deferred()

        key_path = os.path.expanduser('~/.mcloud/%s.key' % self.host)
        crt_path = os.path.expanduser('~/.mcloud/%s.crt' % self.host)

        class NoKeyError(Exception):
            pass

        try:
            if not self.no_ssl and self.host != '127.0.0.1':

                if not os.path.exists(key_path):
github CPChain / pdash / cpchain / wallet / components / preview.py View on Github external
def run_client(self):
        self.factory = WebSocketClientFactory(self.ws_url + '?action=subscribe')
        self.factory.protocol = MyClientProtocol

        def handler(record):
            self.stream.append(record)
        self.factory.handler = handler
        connectWS(self.factory)
github crossbario / autobahn-python / examples / twisted / websocket / reconnecting / client.py View on Github external
self.factory.reactor.callLater(1, hello)

        # start sending messages every second ..
        hello()

    def onMessage(self, payload, isBinary):
        if isBinary:
            print("Binary message received: {0} bytes".format(len(payload)))
        else:
            print("Text message received: {0}".format(payload.decode('utf8')))

    def onClose(self, wasClean, code, reason):
        print("WebSocket connection closed: {0}".format(reason))


class MyClientFactory(WebSocketClientFactory, ReconnectingClientFactory):

    protocol = MyClientProtocol

    def clientConnectionFailed(self, connector, reason):
        print("Client connection failed .. retrying ..")
        self.retry(connector)

    def clientConnectionLost(self, connector, reason):
        print("Client connection lost .. retrying ..")
        self.retry(connector)


if __name__ == '__main__':

    import sys
github warner / magic-wormhole / src / wormhole / twisted / transcribe.py View on Github external
def buildProtocol(self, addr):
        proto = websocket.WebSocketClientFactory.buildProtocol(self, addr)
        proto.wormhole = self.wormhole
        proto.wormhole_open = False
        return proto
github datawire / quark / runtime / twisted / quark_twisted_runtime.py View on Github external
def __init__(self, *args, **kwargs):
        WebSocketClientFactory.__init__(self, *args, **kwargs)
github quedexnet / python-api / quedex_api / user_stream_client.py View on Github external
self.factory.user_stream.initialize()

  def onMessage(self, payload, isbinary):
    # explicit decode for Python 3 compatibility
    self.factory.user_stream.on_message(payload.decode('utf8'))

  def onClose(self, wasclean, code, reason):
    if not wasclean:
      self.factory.user_stream.on_error(
        Exception('WebSocket closed with error - %s : %s' % (code, reason))
      )
    else:
      self.factory.user_stream.on_disconnect('WebSocket closed cleanly - %s : %s' % (code, reason))


class UserStreamClientFactory(WebSocketClientFactory):
  protocol = UserStreamClientProtocol

  def __init__(self, user_stream):
    super(UserStreamClientFactory, self).__init__(user_stream.user_stream_url)
    self.user_stream = user_stream
github crossbario / autobahn-python / autobahn / autobahn / wamp1 / protocol.py View on Github external
:param topicUri: URI or CURIE of topic to unsubscribe from.
      :type topicUri: str
      """
      if type(topicUri) not in [unicode, str]:
         raise Exception("invalid type for parameter 'topicUri' - must be string (was %s)" % type(topicUri))

      turi = self.prefixes.resolveOrPass(topicUri) ### PFX - keep
      if self.subscriptions.has_key(turi):
         msg = [WampProtocol.MESSAGE_TYPEID_UNSUBSCRIBE, topicUri]
         o = self.factory._serialize(msg)
         self.sendMessage(o)
         del self.subscriptions[turi]



class WampClientFactory(WebSocketClientFactory, WampFactory):
   """
   Twisted client factory for WAMP.
   """

   protocol = WampClientProtocol

   def __init__(self,
                url,
                debug = False,
                debugCodePaths = False,
                debugWamp = False,
                debugApp = False,
                reactor = None):
      self.debugWamp = debugWamp
      self.debugApp = debugApp
      WebSocketClientFactory.__init__(self,
github crossbario / autobahn-python / autobahn / autobahn / wamp1 / wamp.py View on Github external
:param topicUri: URI or CURIE of topic to unsubscribe from.
      :type topicUri: str
      """
      if type(topicUri) not in [unicode, str]:
         raise Exception("invalid type for parameter 'topicUri' - must be string (was %s)" % type(topicUri))

      turi = self.prefixes.resolveOrPass(topicUri) ### PFX - keep
      if self.subscriptions.has_key(turi):
         msg = [WampProtocol.MESSAGE_TYPEID_UNSUBSCRIBE, topicUri]
         o = self.factory._serialize(msg)
         self.sendMessage(o)
         del self.subscriptions[turi]



class WampClientFactory(WebSocketClientFactory, WampFactory):
   """
   Twisted client factory for WAMP.
   """

   protocol = WampClientProtocol

   def __init__(self,
                url,
                debug = False,
                debugCodePaths = False,
                debugWamp = False,
                debugApp = False,
                reactor = None):
      self.debugWamp = debugWamp
      self.debugApp = debugApp
      WebSocketClientFactory.__init__(self,
github mahendrakalkura / diffusion / modules / diffusion.py View on Github external
self._connection.disconnect()

    def pre_connect(self):
        log.msg('connecting...')

    def post_connect(self):
        log.msg('connected')

    def pre_message(self):
        log.msg('receiving message...')

    def post_message(self, diffusion_message):
        log.msg('received message: %s' % diffusion_message)


class DiffusionFactory(WebSocketClientFactory, ReconnectingClientFactory):
    """
    maxDelay = 3600 (seconds)
    initialDelay = 1.0 (seconds)
    factor = 2.7182818284590451 # (math.e)
    jitter = 0.11962656472
    Reference: https://github.com/twisted/twisted/blob/trunk/src/twisted/internet/protocol.py#L332
    """

    def clientConnectionFailed(self, connector, reason):
        self.retry(connector)

    def clientConnectionLost(self, connector, reason):
        self.retry(connector)


class DiffusionMessage(object):
github 4acoin / 4acoin / server.py View on Github external
def addnewnode(host):
    ws = "ws://{}:9000".format(host)
    #factory = WebSocketClientFactory(u"ws://127.0.0.1:9000")
    factory = WebSocketClientFactory(ws)
    factory.protocol = MyClientProtocol
    reactor.connectTCP(host, 9000, factory)