Exemplo n.º 1
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 = AutobahnClientFactory(debug = False)
   factory.protocol = SimpleClientProtocol
   reactor.connectTCP("localhost", 9000, factory)
   reactor.run()
Exemplo n.º 2
0
      print "ERROR: %s ('%s')" % (erroruri, errodesc)

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

   def onFoobar(self, arg):
      print "FOOBAR", arg
      arg[3].addCallback(self.onFoobar)

   def onOpen(self):

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

      self.subscribe("event:foobar").addCallback(self.onFoobar)

      self.publish("event:foobar", {"name": "foo", "value": "bar", "num": 666})
      self.publish("event:foobar", {"name": "foo", "value": "bar", "num": 666})
      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 = AutobahnClientFactory(debug = False)
   factory.protocol = ClientProtocol
   reactor.connectTCP("localhost", 9000, factory)
   reactor.run()
Exemplo n.º 3
0
import sys
from twisted.python import log
from twisted.internet import reactor
from autobahn.autobahn import AutobahnClientFactory, AutobahnClientProtocol


class KeyValueClientProtocol(AutobahnClientProtocol):

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

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

   def get(self, keys):
      for key in keys:
         self.call("keyvalue:get", key).addCallback(lambda value, key = key: self.show(key, value))

   def onOpen(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 = AutobahnClientFactory(debug = False)
   factory.protocol = KeyValueClientProtocol
   reactor.connectTCP("localhost", 9000, factory)
   reactor.run()