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 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()
""" 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.web.static import File 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()
@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()
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, gamechannel,
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 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()
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()
## 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()
## register a URI and all URIs having the string as prefix as PubSub topic #self.registerForPubSub("http://example.com/event/simple", True) ## register any URI (string) as topic #self.registerForPubSub("", True) ## register a topic handler to control topic subscriptions/publications self.topicservice = MyTopicService([1, 3, 7]) self.registerHandlerForPubSub(self.topicservice, "http://example.com/event/") 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=True) factory.protocol = MyServerProtocol factory.setProtocolOptions(allowHixie76=True) listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(8080, web) 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()
## 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()
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()