예제 #1
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()
예제 #2
0
파일: server.py 프로젝트: nnseva/dtx-core
 def connect(cls, uri, debug=False):
     client_factory = WampClientFactory(uri)
     client_factory.uri = uri
     client_factory.protocol = cls
     connectWS(client_factory)
     return client_factory
예제 #3
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()
예제 #4
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()
예제 #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

예제 #6
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()
예제 #7
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()
예제 #8
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()
예제 #9
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()
예제 #10
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
예제 #11
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()
예제 #12
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
예제 #13
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()