def __init__(self, test, peerIndex, onReady, onGone): WampClientFactory.__init__(self, test.testee.url) self.test = test self.peerIndex = peerIndex self.onReady = onReady self.onGone = onGone self.proto = None
def _connectClient(self, connected, opened, clientDisconnected): factory = WampClientFactory('ws://localhost:9000', debugWamp=True) factory.protocol = ClientProtocol factory.onConnectionMade = connected factory.onSessionOpen = opened factory.onConnectionLost = clientDisconnected self.factory = factory return connectWS(factory)
def __init__(self, peerIndex, onReady, onGone, test, result): assert(self.protocol) WampClientFactory.__init__(self, test.testee.url) self.peerIndex = peerIndex self.onReady = onReady self.onGone = onGone self.test = test self.result = result self.proto = None
def __init__( self, host, auth=None ): DEBUG = False f = WampClientFactory( "ws://%s:2001" % host, debugWamp = DEBUG) f.protocol = WorkflowClientProtocol f.rpcAuth = auth f.cnx = self self.session = None self.__factory = f self.nextRequestId = 1 self.__pending = { 0: [None,threading.Event()] } self.__thread = threading.Thread( target=self.__run ) self.__thread.daemon = True self.__thread.start()
def __init__(self, options, debug): self.options = options self.user = "******" self.password = options["password"] self.command = options["command"] if self.command == 'connect': self.reconnect = True else: self.reconnect = False if options["spec"]: self.config = json.loads(open(options["spec"]).read()) else: self.config = None WampClientFactory.__init__(self, options["wsuri"], debugWamp = debug)
def __init__(self, config): WampClientFactory.__init__(self, config.wsuri, debugWamp = config.debug) 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)
def publisher(c_name="all", debug=True): log.startLogging(sys.stdout) if c_name != "all": channel_name = "notifications:%s" % c_name else: channel_name = "notifications:all" #print "user name in Publisher: ", channel_name PUBSUB.subscribe(channel_name) ''' factory = WampClientFactory("ws://%s:9000" % socket.gethostname(), debugWamp=debug) ''' factory = WampClientFactory("ws://localhost:9000", debugWamp=debug) factory.protocol = PubSubClient1 connectWS(factory) reactor.run()
def connect(self): if self.client: self.logger.debug('already connected to %s' % self.url) return broadcaster = self self.logger.debug('trying to connect to %s' % self.url) class BroadcastClientProtocol(WampClientProtocol): def onSessionOpen(self): broadcaster.client = self broadcaster.logger.info('connected to broadcast-server %s' % broadcaster.url) broadcaster.onSessionOpen() self.factory = WampClientFactory(self.url) self.factory.protocol = BroadcastClientProtocol reactor.connectTCP(self.host, self.port, self.factory)
def __init__(self, case, onReady, onGone, subscribeTopics): WampClientFactory.__init__(self, case.url, debug=case.debugWs, debugWamp=case.debugWamp) self.case = case self.onReady = onReady self.onGone = onGone self.subscribeTopics = subscribeTopics
class KeyValueClientProtocol(WampClientProtocol): 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()
def __init__(self, wsuri, user, password): self.user = user self.password = password WampClientFactory.__init__(self, wsuri)
def __init__(self, command_channel, *args, **kwargs): self.command_channel = command_channel WampClientFactory.__init__(self, *args, **kwargs)
def __init__(self, url, debug = False, debugCodePaths = False, debugWamp = False, debugApp = False): WampClientFactory.__init__(self, url, debug = debug, debugCodePaths = debugCodePaths) self.spiders = {} self.is_first = 0
def logerror(self, e): erroruri, errodesc, errordetails = e.value.args print "ERROR: %s ('%s') - %s" % (erroruri, errodesc, errordetails) def done(self, *args): self.sendClose() reactor.stop() def onSessionOpen(self): # Set the App Prefix self.prefix("moirai", "http://%s/%s/" % (app_domain, app_name)) query = "START n=node(*) RETURN n;" params = {} self.call("moirai:cypher", query, params).addCallbacks(self.nodesFirst) ############## STUFF HAPPENS HERE ############# if __name__ == '__main__': log.startLogging(sys.stdout) factory = WampClientFactory("ws://%s:%s" % (ws_host, ws_port), debugWamp = True) factory.protocol = SimpleClientProtocol connectWS(factory) reactor.run()
"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 = WampClientFactory(debug=False) factory.protocol = MyClientProtocol reactor.connectTCP("localhost", 9000, factory) reactor.run()
class PubSubClient1(WampClientProtocol): def onSessionOpen(self): # Set the App Prefix self.prefix("moirai", "http://%s/%s#" % (app_domain, app_name)) print "Subscribing to %s at port %s" % (app_name, ws_port) # Suscribe to the pubsub self.subscribe("moirai:graph1", self.onApp) def onSimpleEvent(self, topicUri, event): print "Event", topicUri, event def onApp(self, topicUri, event): print app_name, topicUri, event if __name__ == '__main__': log.startLogging(sys.stdout) debug = len(sys.argv) > 1 and sys.argv[1] == 'debug' factory = WampClientFactory("ws://%s:%s" % (ws_host, ws_port), debugWamp=debug) factory.protocol = PubSubClient1 connectWS(factory) reactor.run()
def dataReceived(self, data): self.resetTimeout() print len(data) if len(data) == 11: packet = Packet(data) print packet self._publish(packet.toDict()) reactor.callLater(0.1, self.sendCMD, 'GET') else: log.msg("Received Gargabe") log.msg("LEN: %s " % len(data)) log.msg(data) def lineReceived(self, line): log.msg("Line Received") log.msg(line) if __name__ == '__main__': ##Setup Server wampServerFactory = WampServerFactory("ws://localhost:9000") wampServerFactory.protocol = TSPublisher listenWS(wampServerFactory) ##Setup Client wampClientFactory = WampClientFactory("ws://localhost:9000") wampClientFactory.protocol = TSClient connectWS(wampClientFactory) reactor.run()
def buildProtocol(self, addr): log.msg(u'Connected from {}'.format(addr)) self.resetDelay() return WampClientFactory.buildProtocol(self, addr)
def __init__(self, app): WampClientFactory.__init__(self, app.url, debugWamp = app.debug) self.app = app self.proto = None self.wasConnected = False
def logerror(self, e): erroruri, errodesc, errordetails = e.value.args print "ERROR: %s ('%s') - %s" % (erroruri, errodesc, errordetails) def done(self, *args): self.sendClose() reactor.stop() def onSessionOpen(self): # Set the App Prefix self.prefix("moirai", "http://%s/%s/" % (app_domain, app_name)) query = "START n=node(*) RETURN n;" params = {} self.call("moirai:cypher", query, params).addCallbacks(self.nodesFirst) ############## STUFF HAPPENS HERE ############# if __name__ == '__main__': log.startLogging(sys.stdout) factory = WampClientFactory("ws://%s:%s" % (ws_host, ws_port), debugWamp=True) factory.protocol = SimpleClientProtocol connectWS(factory) reactor.run()
class GephiClientProtocol(WebSocketClientProtocol): def onOpen(self): print "connected to Gephi" def onMessage(self, msg, binary): if not binary: obj = json.loads(msg) self.factory.forwarder.publish(GEPHI_TOPIC_URI + "1", obj) class GephiForwardingProtocol(WampClientProtocol): def onSessionOpen(self): print "connected to WAMP server" factory = WebSocketClientFactory(GEPHI_SERVER_URL) factory.protocol = GephiClientProtocol factory.forwarder = self connectWS(factory) if __name__ == '__main__': log.startLogging(sys.stdout) debug = len(sys.argv) > 1 and sys.argv[1] == 'debug' factory = WampClientFactory(WAMP_SERVER_URL, debugWamp=debug) factory.protocol = GephiForwardingProtocol connectWS(factory) reactor.run()
print "connected to Gephi" def onMessage(self, msg, binary): if not binary: obj = json.loads(msg) self.factory.forwarder.publish(GEPHI_TOPIC_URI + "1", obj) class GephiForwardingProtocol(WampClientProtocol): def onSessionOpen(self): print "connected to WAMP server" factory = WebSocketClientFactory(GEPHI_SERVER_URL) factory.protocol = GephiClientProtocol factory.forwarder = self connectWS(factory) if __name__ == '__main__': log.startLogging(sys.stdout) debug = len(sys.argv) > 1 and sys.argv[1] == 'debug' factory = WampClientFactory(WAMP_SERVER_URL, debugWamp = debug) factory.protocol = GephiForwardingProtocol connectWS(factory) reactor.run()
self.prefix("pups", "http://spkvexample.com/pups") self.addPuppy() ## Make changes to the list of dogs here, then run the script to publish them to the server ## NOTE: currently the client is hard-coded to talk to localhost def addPuppy(self): self.publish("pups:/", { str(15): { "name": "Dozer", "about": "Victorian bulldog", "favorite": False } # , str(13): { # "name": "Mozart", # "about": "The prodigal pup", # "favorite": False # } }) if __name__ == '__main__': log.startLogging(sys.stdout) debug = len(sys.argv) > 1 and sys.argv[1] == 'debug' factory = WampClientFactory("ws://localhost:9000", debugWamp = debug) factory.protocol = PubSubClient1 connectWS(factory) reactor.run()
def onPong(self, payload): id = payload[:16] l = len(payload) - 16 now = datetime.datetime.utcnow() if self.beats.has_key(id): rtt_ms = (now - self.beats[id]).total_seconds() * 1000. print "Got heartbeat: " + id, l, rtt_ms if __name__ == '__main__': if len(sys.argv) < 2: print "Need the WebSocket server address, i.e. ws://localhost:9000" sys.exit(1) log.startLogging(sys.stdout) debug = False #factory = WebSocketClientFactory(sys.argv[1], debug = True, debugCodePaths = True) factory = WampClientFactory(sys.argv[1], debug = debug, debugCodePaths = True, debugWamp = debug) factory.protocol = HeartbeatClientProtocol connectWS(factory) reactor.run()
from autobahn.websocket import connectWS from autobahn.wamp import WampClientFactory, \ WampClientProtocol class PubSubClient1(WampClientProtocol): def onSessionOpen(self): self.subscribe("http://example.com/simple", self.onSimpleEvent) self.sendSimpleEvent() def onSimpleEvent(self, topicUri, event): print "Event", topicUri, event def sendSimpleEvent(self): self.publish("http://example.com/simple", "Hello!") reactor.callLater(2, self.sendSimpleEvent) if __name__ == '__main__': log.startLogging(sys.stdout) debug = len(sys.argv) > 1 and sys.argv[1] == 'debug' factory = WampClientFactory("ws://mozart.kawigi.com:9000", debugWamp=debug) factory.protocol = PubSubClient1 connectWS(factory) reactor.run()
def printEvent(self, topicUri, event): print "printEvent", topicUri, event def sendSimpleEvent(self): self.publish("http://example.com/simple", None) 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()
def onOpen(self): self.bm = BluetoothManager("07:12:05:16:67:00", 1) self.bm.registerListener(self.onBluetoothMessage) self.bm.start() def onSessionOpen(self): self.subscribe("http://leddimmer.unserHaus.name/event", self.onSimpleEvent) def onSimpleEvent(self, topicUri, event): self.sendBluetoothMessage(event) def onBluetoothMessage(self, message): #print message self.publish("http://leddimmer.unserHaus.name/event", message) def sendBluetoothMessage(self, message): self.bm.sendMessage(message) if __name__ == '__main__': log.startLogging(sys.stdout) debug = len(sys.argv) > 1 and sys.argv[1] == 'debug' debug = True factory = WampClientFactory("ws://localhost:9000", debugWamp=debug) factory.protocol = PubSubClient1 factory.setProtocolOptions(tcpNoDelay=True) connectWS(factory) reactor.run()
def connectionFailed(self): self._get_prot.errback(Exception('connection failed')) return WampClientFactory.connectionFailed(self)
def __init__(self, options, reactor): self.options = options self.done = False WampClientFactory.__init__(self, self.options.server, debugWamp = self.options.debug)
def start( cls ): f = WampClientFactory( "ws://localhost:2001", debugWamp=True ) f.protocol = NotificationProtocol connectWS(f)
def __init__(self, app, clientId): WampClientFactory.__init__(self, ARGS.websocket_url, ARGS.debug) self.protocol = None self.app = app self.clientId = clientId self.failureRecorded = False