def __init__(self, url): WampServerFactory.__init__(self, url) for sensor in sensorlist: if sensor[:3].upper() == 'ENV': self.envProtocol = EnvProtocol(self,sensor.strip(), outputdir) if sensor[:2].upper() == 'OW': self.owProtocol = OwProtocol(self,owport,outputdir) if sensor[:3].upper() == 'POS': self.pos1Protocol = Pos1Protocol(self,sensor.strip(), outputdir) if sensor[:3].upper() == 'KER': print "Test1:", sensor.strip self.kernProtocol = KernProtocol(self,sensor.strip(), outputdir) if sensor[:3].upper() == 'ARD': self.arduinoProtocol = ArduinoProtocol(self, sensor.strip(), outputdir) if sensor[:3].upper() == 'SER': port = serialport+portdict[sensor] baudrate = baudratedict[sensor] self.callProtocol = CallProtocol(self,sensor.strip(), outputdir,port,baudrate) if sensor[:3].upper() == 'PAL': self.palmacqProtocol = PalmAcqProtocol(self, sensor.strip(), outputdir) if sensor[:3].upper() == 'LEM': self.lemiProtocol = LemiProtocol(self,sensor.strip(),sensor[0]+sensor[4:7], outputdir) if sensor[:3].upper() == 'G82': self.csProtocol = CsProtocol(self,sensor.strip(), outputdir) if sensor[:3].upper() == 'GSM': self.gsm90Protocol = GSM90Protocol(self,sensor.strip(), outputdir) if sensor[:3].upper() == 'G19': self.gsm19Protocol = GSM19Protocol(self,sensor.strip(), outputdir)
def __init__(self, url, debugSerial=False, debugWs=False, debugWamp=False): WampServerFactory.__init__(self, url, debug=debugWs, debugWamp=debugWamp) self.debugSerial = debugSerial self.mcuProtocol = McuProtocol(self)
def execute(self): factory = WampServerFactory("ws://localhost:17998", debug = False, debugWamp = False) factory.protocol = PlywoodWebSocketServerProtocol factory.setProtocolOptions(allowHixie76 = True) listenWS(factory) reactor.run(installSignalHandlers=0)
def __init__(self, url, debug = False): WampServerFactory.__init__(self, url, debugWamp = debug) self.setProtocolOptions(allowHixie76 = True) ## the key-value store resides on the factory object, since it is to ## be shared among all client connections self.keyvalue = KeyValue("keyvalue.dat") decimal.getcontext().prec = 20
def __init__(self, url, debug=False): WampServerFactory.__init__(self, url, debugWamp=debug) self.setProtocolOptions(allowHixie76=True) ## the key-value store resides on the factory object, since it is to ## be shared among all client connections self.keyvalue = KeyValue("keyvalue.dat") decimal.getcontext().prec = 20
def __init__(self, uri, apps, debug=False): WampServerFactory.__init__(self, uri, debug) self.apps = [] for app in apps: if isinstance(app, (str)): mod = import_module(app) else: mod = app log.msg(u"Registering WAMP module {}".format(unicode(mod))) self.apps.append(mod)
def __init__(self, uri, apps, debug=False): WampServerFactory.__init__(self, uri, debug) self.apps = [] for app in apps: if (isinstance(app, (str))): mod = import_module(app) else: mod = app log.msg(u'Registering WAMP module {}'.format(unicode(mod))) self.apps.append(mod)
def __init__(self, config): self.config = config WampServerFactory.__init__(self, config.wsuri, debugWamp = config.debug) self.setProtocolOptions(failByDrop = False) if config.skiputf8validate: self.setProtocolOptions(utf8validateIncoming = False) if config.allowunmasked: self.setProtocolOptions(requireMaskedClientFrames = False) self.connectedClients = set() print "Load/Latency Broker listening on %s [skiputf8validate = %s, allowunmasked = %s]" % (config.wsuri, config.skiputf8validate, config.allowunmasked) def printstats(): print "%d clients connected" % len(self.connectedClients) reactor.callLater(1, printstats) printstats()
def __init__(self, config): self.config = config WampServerFactory.__init__(self, config.wsuri, debugWamp=config.debug) self.setProtocolOptions(failByDrop=False) if config.skiputf8validate: self.setProtocolOptions(utf8validateIncoming=False) if config.allowunmasked: self.setProtocolOptions(requireMaskedClientFrames=False) self.connectedClients = set() print "Load/Latency Broker listening on %s [skiputf8validate = %s, allowunmasked = %s]" % ( config.wsuri, config.skiputf8validate, config.allowunmasked) def printstats(): print "%d clients connected" % len(self.connectedClients) reactor.callLater(1, printstats) printstats()
def __init__(self, testDb, testRunner, url, debug = False): assert(verifyObject(ITestDb, testDb)) assert(verifyObject(ITestRunner, testRunner)) WampServerFactory.__init__(self, url, debug = True, debugWamp = True) self._testDb = testDb self._testRunner = testRunner
def __init__(self, url, debugSerial = False, debugWs = False, debugWamp = False): WampServerFactory.__init__(self, url, debug = debugWs, debugWamp = debugWamp) self.debugSerial = debugSerial self.mcuProtocol = McuProtocol(self)
A method that we remote by using the exportRpc decorator. """ return x + y def doSub(self, x, y): """ A method that we remote explicitly. """ return x - y if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == 'debug': log.startLogging(sys.stdout) debug = True else: debug = False factory = WampServerFactory("ws://localhost:9000", debugWamp = debug) factory.protocol = RpcServer1Protocol factory.setProtocolOptions(allowHixie76 = True) listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(8080, web) reactor.run()
""" Protocol class for our simple demo WAMP server. """ def onSessionOpen(self): ## When the WAMP session to a client has been established, ## register a single fixed URI as PubSub topic that our ## message broker will handle ## self.registerForPubSub("http://example.com/myEvent1") if __name__ == '__main__': log.startLogging(sys.stdout) ## our WAMP/WebSocket server ## wampFactory = WampServerFactory("ws://localhost:9000", debugWamp=True) wampFactory.protocol = MyPubSubServerProtocol listenWS(wampFactory) ## our Web server (for static Web content) ## webFactory = Site(File(".")) reactor.listenTCP(8080, webFactory) ## run the Twisted network reactor ## reactor.run()
## register RPC endpoints (for now do that manually, keep in sync with perms) if authKey is not None: self.registerForRpc(self, 'http://example.com/procedures/', [MyServerProtocol.hello]) @exportRpc("hello") def hello(self, name): return "Hello back %s!" % name if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == 'debug': log.startLogging(sys.stdout) debug = True else: debug = False factory = WampServerFactory("ws://localhost:9000", debugWamp = debug) factory.protocol = MyServerProtocol listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(8080, web) reactor.run()
## register RPC endpoints (for now do that manually, keep in sync with perms) if authKey is not None: self.registerForRpc(self, 'http://example.com/procedures/', [APIServerProtocol.hello]) @exportRpc("hello") def hello(self, name): return "Hello back %s!" % name if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == 'debug': log.startLogging(sys.stdout) debug = True else: debug = False factory = WampServerFactory("ws://localhost:9000", debugWamp = debug) factory.protocol = ApiServerProtocol listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(8080, web) reactor.run()
def __init__(self, url, debug): WampServerFactory.__init__(self, url, debugWamp = debug) Signal.register = self.register Signal.unregister = self.unregister Signal.publish = self.publish_signal_public self.signals = {}
from autobahn.twisted.websocket import listenWS from autobahn.wamp1.protocol import WampServerFactory, \ WampServerProtocol class DirWatchServerProtocol(WampServerProtocol): def onSessionOpen(self): ## register a URI and all URIs having the string as prefix as PubSub topic self.registerForPubSub("http://dirwatch.autobahn.ws", True) if __name__ == '__main__': log.startLogging(sys.stdout) debug = len(sys.argv) > 1 and sys.argv[1] == 'debug' factory = WampServerFactory("ws://localhost:9000", debugWamp = debug) factory.protocol = DirWatchServerProtocol factory.setProtocolOptions(allowHixie76 = True) listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(8080, web) reactor.run()
def __init__(self, url, debug = False, debugWamp = False): WampServerFactory.__init__(self, url, debug = debug, debugWamp = debugWamp) ## the key-value store resides on the factory object, since it is to ## be shared among all client connections self.keyvalue = KeyValue("keyvalue.dat")
## register RPC endpoints (for now do that manually, keep in sync with perms) if authKey is None: self.registerForRpc(self, 'http://example.com/procedures/', [MyServerProtocol.getUsers]) @exportRpc("getusers") def getUsers(self): return self.USERS.keys() if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == 'debug': log.startLogging(sys.stdout) debug = True else: debug = False factory = WampServerFactory("ws://localhost:9000", debugWamp = debug) factory.protocol = DbusServerProtocol listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(8080, web) reactor.run()
for key in self.rooms.keys(): if self.rooms[key].getPlayerCount() <= 0: self.rooms.pop(key, None) if __name__ == '__main__': import sys from twisted.python import log log.startLogging(sys.stdout) gameList = {} # Initialize pub/sub factory psfactory = WampServerFactory(wampuri, debugWamp=True) psfactory.protocol = PubSubProtocol listenWS(psfactory) # Initialize client socket factory clientfactory = LobbyDataFactory(wsuri, gameList, psfactory.dispatch, debug=False) clientfactory.protocol = LobbyDataProtocol # Initialize player socket factory playerfactory = PlayerSocketFactory(playeruri, gameList, clientfactory.pushUpdate, psfactory.dispatch,
@exportRpc("wsum") def workerSum(self, list, delay): ## Execute a slow function on thread from background thread pool. def wsum(list): if delay > 0: time.sleep(delay) return self.sum(list) return threads.deferToThread(wsum, list) if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == 'debug': log.startLogging(sys.stdout) debug = True else: debug = False factory = WampServerFactory("ws://localhost:9000", debugWamp = debug) factory.protocol = SimpleServerProtocol factory.setProtocolOptions(allowHixie76 = True) factory.trackTimings = True listenWS(factory) poolSize = 5 print "Thread pool size:", poolSize reactor.suggestThreadPoolSize(poolSize) reactor.run()
self.op = op self.current = num res = str(self.current) if op == "=": self.clear() return res if __name__ == '__main__': decimal.getcontext().prec = 20 if len(sys.argv) > 1 and sys.argv[1] == 'debug': log.startLogging(sys.stdout) debug = True else: debug = False factory = WampServerFactory("ws://localhost:9000", debugWamp = debug) factory.protocol = CalculatorServerProtocol factory.setProtocolOptions(allowHixie76 = True) listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(8080, web) reactor.run()
""" A method that we remote by using the exportRpc decorator. """ return x + y def doSub(self, x, y): """ A method that we remote explicitly. """ return x - y if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == 'debug': log.startLogging(sys.stdout) debug = True else: debug = False factory = WampServerFactory("ws://localhost:9000", debugWamp=debug) factory.protocol = RpcServer1Protocol factory.setProtocolOptions(allowHixie76=True) listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(8080, web) reactor.run()
from twisted.internet import reactor from autobahn.twisted.websocket import listenWS from autobahn.wamp1.protocol import WampServerFactory, WampServerProtocol class MyPubSubServerProtocol(WampServerProtocol): """ Protocol class for our simple demo WAMP server. """ def onSessionOpen(self): ## When the WAMP session to a client has been established, ## register a single fixed URI as PubSub topic that our ## message broker will handle self.registerForPubSub("http://192.168.1.106/messages") if __name__ == '__main__': log.startLogging(sys.stdout) ## our WAMP/WebSocket server wampFactory = WampServerFactory("ws://192.168.1.106:9000", debugWamp=True) wampFactory.protocol = MyPubSubServerProtocol listenWS(wampFactory) ## run the Twisted network reactor reactor.run()
def onSessionOpen(self): ## When the WAMP session to a client has been established, ## register a single fixed URI as PubSub topic that our ## message broker will handle for sensor in sensors: self.registerForPubSub(sensor) if __name__ == '__main__': log.startLogging(sys.stdout) parser = argparse.ArgumentParser() parser.add_argument('-p', '--port', type=str) parser.add_argument('-t', '--tcp', type=int) parser.add_argument('-s', '--sensors', type=str) args = parser.parse_args() port = args.port tcp = args.tcp sensors = ast.literal_eval(args.sensors) wampFactory = WampServerFactory("ws://" + constants.BROKER_HOST + ":" + str(port), debugWamp = False) wampFactory.protocol = MyPubSubServerProtocol listenWS(wampFactory) ## our Web server (for static Web content) webFactory = Site(File(".")) reactor.listenTCP(int(tcp), webFactory) ## run the Twisted network reactor reactor.run()
## register PubSub topics from the auth permissions self.registerForPubSubFromPermissions(perms['permissions']) ## register RPC endpoints (for now do that manually, keep in sync with perms) if authKey is not None: self.registerForRpc(self, 'http://example.com/procedures/', [APIServerProtocol.hello]) @exportRpc("hello") def hello(self, name): return "Hello back %s!" % name if __name__ == '__main__': if len(sys.argv) > 1 and sys.argv[1] == 'debug': log.startLogging(sys.stdout) debug = True else: debug = False factory = WampServerFactory("ws://localhost:9000", debugWamp=debug) factory.protocol = ApiServerProtocol listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(8080, web) reactor.run()