Example #1
0
    def __init__(self, config):

        WampClientFactory.__init__(self, config.wsuri, debugWamp=config.debug)

        self.config = config
        self.id = 0
        self.batchid = 0
        self.publishedCnt = 0

        self.setProtocolOptions(failByDrop=False)

        if config.skiputf8validate:
            self.setProtocolOptions(utf8validateIncoming=False)

        if config.skipmasking:
            self.setProtocolOptions(maskClientFrames=False)
Example #2
0
   def __init__(self, config):

      WampClientFactory.__init__(self, config.wsuri, debugWamp = config.debug)

      self.config = config
      self.id = 0
      self.batchid = 0
      self.publishedCnt = 0

      self.setProtocolOptions(failByDrop = False)

      if config.skiputf8validate:
         self.setProtocolOptions(utf8validateIncoming = False)

      if config.skipmasking:
         self.setProtocolOptions(maskClientFrames = False)
Example #3
0
   def __init__(self, config, d):

      WampClientFactory.__init__(self, config.wsuri, debugWamp = config.debug)

      self._ready = d

      self.config = config
      self.receivedCnt = 0
      self.receivedRtts = []

      self.setProtocolOptions(failByDrop = False)

      if config.skiputf8validate:
         self.setProtocolOptions(utf8validateIncoming = False)

      if config.skipmasking:
         self.setProtocolOptions(maskClientFrames = False)
Example #4
0
    def __init__(self, config, d):

        WampClientFactory.__init__(self, config.wsuri, debugWamp=config.debug)

        self._ready = d

        self.config = config
        self.receivedCnt = 0
        self.receivedRtts = []

        self.setProtocolOptions(failByDrop=False)

        if config.skiputf8validate:
            self.setProtocolOptions(utf8validateIncoming=False)

        if config.skipmasking:
            self.setProtocolOptions(maskClientFrames=False)
Example #5
0
            print line
            if len(line) < 2:
                try:
                    s.append(line[0].split())
                except:
                    # Empty line for example
                    pass
            else:
                s.append(line)
    print s
    if os.path.exists(destowfile):
        with open(destowfile,'rb') as f:
            reader = csv.reader(f)
            o = [line for line in reader]
        print o

    factory = WampClientFactory("ws://"+clientip+":9100", debugWamp = False)
    cl.sendparameter(clientname,clientip,destpath,dest,stationid,sshcredlst,s,o,printdata,dbcredlst)
    factory.protocol = cl.PubSubClient
    connectWS(factory)

    reactor.run()

    try:
        cursor.close()
        db.close()
        log.msg("DB closed")
    except:
        pass

Example #6
0
   def printEvent(self, topicUri, event):
      print "printEvent", topicUri, event

   def sendSimpleEvent(self):
      self.publish("http://example.com/simple", "Hello!")
#      self.publish("http://example.com/simple", "Hello!", excludeMe = False, eligible = [self.session_id])
      reactor.callLater(2, self.sendSimpleEvent)

   def onEvent1(self, topicUri, event):
      self.counter += 1
      self.publish("event:myevent2", {"trigger": event, "counter": self.counter})

   def onSessionOpen(self):

      self.counter = 0
      self.subscribe("http://example.com/simple", self.printEvent)
      self.sendSimpleEvent()

      self.prefix("event", "http://example.com/event#")
      self.subscribe("event:myevent1", self.onEvent1)
      self.subscribe("event:myevent2", self.printEvent)


if __name__ == '__main__':

   log.startLogging(sys.stdout)
   factory = WampClientFactory("ws://localhost:9000")
   factory.protocol = MyClientProtocol
   connectWS(factory)
   reactor.run()
Example #7
0
 def __init__(self, wsuri, user, password):
     self.user = user
     self.password = password
     WampClientFactory.__init__(self, wsuri)
Example #8
0
class KeyValueClientProtocol(WampClientProtocol):

   # noinspection PyUnusedLocal
   def done(self, *args):
      self.sendClose()
      reactor.stop()

   def show(self, key, value):
      print key, value

   def get(self, keys):
      defs = []
      for key in keys:
         d = self.call("keyvalue:get", key).addCallback(lambda value, key = key: self.show(key, value))
         defs.append(d)
      return DeferredList(defs)

   def onSessionOpen(self):
      self.prefix("keyvalue", "http://example.com/simple/keyvalue#")
      self.call("keyvalue:keys").addCallbacks(self.get).addCallback(self.done)


if __name__ == '__main__':

   log.startLogging(sys.stdout)
   factory = WampClientFactory("ws://localhost:8080/ws")
   factory.protocol = KeyValueClientProtocol
   connectWS(factory)
   reactor.run()
Example #9
0
        d3 = self.call("calc:sum", [1, 2, 3, 4, 5]).addCallback(self.show)

        d4 = self.call("calc:square", 23).addCallback(lambda res: \
                           self.call("calc:sqrt", res)).addCallback(self.show)

        d5 = self.call("calc:sqrt", -1).addCallbacks(self.show, self.logerror)

        d6 = self.call("calc:square",
                       1001).addCallbacks(self.show, self.logerror)

        d7 = self.call("calc:asum", [1, 2, 3]).addCallback(self.show)

        d8 = self.call("calc:sum", [4, 5, 6]).addCallback(self.show)

        d9 = self.call("calc:pickySum",
                       range(0, 30)).addCallbacks(self.show, self.logerror)

        ## we want to shutdown the client exactly when all deferreds are finished
        DeferredList([d1, d2, d3, d4, d5, d6, d7, d8,
                      d9]).addCallback(self.done)


if __name__ == '__main__':

    log.startLogging(sys.stdout)
    factory = WampClientFactory("ws://localhost:9000", debugWamp=True)
    factory.protocol = SimpleClientProtocol
    connectWS(factory)
    reactor.run()
Example #10
0
 def __init__(self, app):
    WampClientFactory.__init__(self, app.url, debugWamp = app.debug)
    self.app = app
    self.proto = None
    self.wasConnected = False
Example #11
0
        d.addCallbacks(self.onAuthSuccess, self.onAuthError)

    def onClose(self, wasClean, code, reason):
        reactor.stop()

    def onAuthSuccess(self, permissions):
        print "Authentication Success!", permissions
        self.publish("http://example.com/topics/mytopic1", "Hello, world!")
        d = self.call("http://example.com/procedures/hello", "Foobar")
        d.addBoth(pprint)
        d.addBoth(self.sendClose)

    def onAuthError(self, e):
        uri, desc, details = e.value.args
        print "Authentication Error!", uri, desc, details


if __name__ == '__main__':

    if len(sys.argv) > 1 and sys.argv[1] == 'debug':
        log.startLogging(sys.stdout)
        debug = True
    else:
        debug = False

    log.startLogging(sys.stdout)
    factory = WampClientFactory("ws://localhost:9000", debugWamp=debug)
    factory.protocol = MyClientProtocol
    connectWS(factory)
    reactor.run()
Example #12
0
   lat = args.lat
   lng = args.lng
   registry_address = args.registry
   max_brokers = args.maxbrokers
   radius = args.radius
   output = args.outputfilename

   ## loops through brokers in broker list, connecting to each
   if (location != None):
      use_xy = False
      broker_list = request_brokers_l(registry_address, location, radius, max_brokers, sensors)
   else:
      if (lat == None or lng == None):
         print "ERROR - must have either location (-l) or latitude (-x) and longitude (-y)"
         exit()
      use_xy = True
      broker_list = request_brokers_xy(registry_address, lat, lng, radius, max_brokers, sensors)

   print "BROKER LIST : " + str(broker_list)
   if (broker_list):
      io_file = open("output/" + output + ".csv", 'w+')
      io_file.write("sensor,lat,lng,data,timestamp,time\n")
      for broker in broker_list:
         wsuri = broker['broker_address']
         print "Connecting to", wsuri
         factory = WampClientFactory(wsuri, debugWamp = False)
         factory.protocol = SensorDataConsumerClientProtocol
         connectWS(factory)
      
      reactor.run()
Example #13
0
        pass

    s,o = [],[]
    with open(destsensfile,'rb') as f:
        reader = csv.reader(f)
        s = []
        for line in reader:
            if len(line) < 2:
                s.append(line[0].split())
            else:
                s.append(line)
    print s
    with open(destowfile,'rb') as f:
        reader = csv.reader(f)
        o = [line for line in reader]
    print o

    factory = WampClientFactory("ws://"+clientip+":9100", debugWamp = False)
    cl.sendparameter(clientname,clientip,destpath,dest,stationid,sshcredlst,s,o,printdata,dbcredlst)
    factory.protocol = cl.PubSubClient
    connectWS(factory)

    reactor.run()

    try:
        cursor.close()
        db.close()
        log.msg("DB closed")
    except:
        pass
Example #14
0
 def __init__(self, wsuri, user, password):
    self.user = user
    self.password = password
    WampClientFactory.__init__(self, wsuri)
Example #15
0
      print "myfun:1", val

      r = yield self.mysubfun(val)
      print "myfun:2", r

      returnValue(r * 10)


   @inlineCallbacks
   def mysubfun(self, val):

      print "mysubfun:1", val

      r1 = yield self.call("calc:asum", [1, 2, 3, val])
      print "mysubfun:2", r1

      r2 = yield self.call("calc:square", r1)
      print "mysubfun:3", r2

      returnValue(r2 + 1)


if __name__ == '__main__':

   log.startLogging(sys.stdout)
   factory = WampClientFactory("ws://localhost:9000")
   factory.protocol = SimpleClientProtocol
   connectWS(factory)
   reactor.run()
Example #16
0
 def connect(cls, uri, debug=False):
     client_factory = WampClientFactory(uri)
     client_factory.uri = uri
     client_factory.protocol = cls
     connectWS(client_factory)
     return client_factory
Example #17
0
      erroruri, errodesc = e.value.args
      print "ERROR: %s ('%s')" % (erroruri, errodesc)

   def done(self, *args):
      self.sendClose()

   def onFoobar(self, topicUri, event):
      print "FOOBAR", topicUri, event

   def onSessionOpen(self):

      self.prefix("event", "http://example.com/event/")

      self.subscribe("event:foobar1", self.onFoobar)
      self.subscribe("event:foobar2", self.onFoobar)

      self.publish("event:foobar1", {"count": 666})
      self.publish("event:foobar2", {"count": 67})
      self.publish("event:foobar-extended", {"name": "foo", "value": "bar", "num": 42})
      self.publish("event:foobar-limited", {"name": "foo", "value": "bar", "num": 23})

      #self.done()


if __name__ == '__main__':

   log.startLogging(sys.stdout)
   factory = WampClientFactory("ws://localhost:9000")
   factory.protocol = MyClientProtocol
   connectWS(factory)
   reactor.run()
Example #18
0
            })
            reactor.callLater(2, sendMyEvent1)

        sendMyEvent1()

    def onClose(self, wasClean, code, reason):
        print "Connection closed", reason
        reactor.stop()


if __name__ == '__main__':

    log.startLogging(sys.stdout)

    if len(sys.argv) > 1:
        wsuri = sys.argv[1]
    else:
        wsuri = "ws://localhost:9000"

    print "Connecting to", wsuri

    ## our WAMP/WebSocket client
    ##
    factory = WampClientFactory(wsuri, debugWamp=False)
    factory.protocol = MyPubSubClientProtocol
    connectWS(factory)

    ## run the Twisted network reactor
    ##
    reactor.run()
Example #19
0
    registry_address = args.registry
    max_brokers = args.maxbrokers
    radius = args.radius
    output = args.outputfilename

    ## loops through brokers in broker list, connecting to each
    if (location != None):
        use_xy = False
        broker_list = request_brokers_l(registry_address, location, radius,
                                        max_brokers, sensors)
    else:
        if (lat == None or lng == None):
            print "ERROR - must have either location (-l) or latitude (-x) and longitude (-y)"
            exit()
        use_xy = True
        broker_list = request_brokers_xy(registry_address, lat, lng, radius,
                                         max_brokers, sensors)

    print "BROKER LIST : " + str(broker_list)
    if (broker_list):
        io_file = open("output/" + output + ".csv", 'w+')
        io_file.write("sensor,lat,lng,data,timestamp,time\n")
        for broker in broker_list:
            wsuri = broker['broker_address']
            print "Connecting to", wsuri
            factory = WampClientFactory(wsuri, debugWamp=False)
            factory.protocol = SensorDataConsumerClientProtocol
            connectWS(factory)

        reactor.run()
Example #20
0
   def __init__(self, *args, **kwargs):
      WampClientFactory.__init__(self, *args, **kwargs)

      self.protocol_instance = None
      self.base_client = None
Example #21
0
 def connect(cls, uri, debug=False):
     client_factory = WampClientFactory(uri)
     client_factory.uri = uri
     client_factory.protocol = cls
     connectWS(client_factory)
     return client_factory
Example #22
0
      sendMyEvent1()


   def onClose(self, wasClean, code, reason):
      print "Connection closed", reason
      reactor.stop()



if __name__ == '__main__':

   log.startLogging(sys.stdout)

   if len(sys.argv) > 1:
      wsuri = sys.argv[1]
   else:
      wsuri = "ws://localhost:9000"

   print "Connecting to", wsuri

   ## our WAMP/WebSocket client
   ##
   factory = WampClientFactory(wsuri, debugWamp = False)
   factory.protocol = MyPubSubClientProtocol
   connectWS(factory)

   ## run the Twisted network reactor
   ##
   reactor.run()