def __init__(self, port = 9000, debug = False): self.port = port self.debug = debug factory = WampServerFactory("ws://localhost:%d" % self.port, debug = self.debug) factory.protocol = LabspiralServerProtocol factory.setProtocolOptions(allowHixie76 = True) # needed if Hixie76 is to be supported self.factory = factory
def runwamp(logfile=None, debug=True): if logfile is None: log.startLogging(sys.stdout) ''' factory = WampServerFactory("ws://%s:9000" % socket.gethostname(), debugWamp=debug) ''' factory = "" host_name = socket.gethostname() if host_name == 'ip-172-31-29-49': factory = WampServerFactory("ws://oposod.com:9000", debugWamp=None) else: factory = WampServerFactory("ws://localhost:9000", debugWamp=debug) factory.protocol = PubSubServer1 factory.setProtocolOptions(allowHixie76=True) listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(9090, web) reactor.run()
def runServer(): if len(sys.argv) > 1 and sys.argv[1] == 'debug': log.startLogging(sys.stdout) debug = True else: debug = False factory = WampServerFactory("ws://localhost:9000", debug=False, debugCodePaths=False, debugWamp=debug, debugApp=False) factory.protocol = AppServerProtocol factory.setProtocolOptions(allowHixie76 = True) listenWS(factory) webdir = File(".") web = Site(webdir) reactor.listenTCP(8080, web) reactor.run(installSignalHandlers=0)
def run_server (): reactor.listenTCP(8789, pb.PBServerFactory(ExperimentMarshal())) log.msg("PB listening on port 8789") factory = WampServerFactory("ws://localhost:9000") factory.protocol = LabspiralServerProtocol listenWS(factory) log.msg("WS listening on port 9000") ExperimentMarshal.publish = factory.dispatch root = resource.Resource() root.putChild("", Root()) root.putChild("experiments", ExperimentList()) root.putChild("resources", static.File("resources")) site = server.Site(root) reactor.listenTCP(8001, site) log.msg("HTTP listening on port 8001") reactor.run() log.msg("Server stopped")
pubsub=WampServerProtocol.SUBSCRIBE) self.registerForPubSub("http://example.com/event#", True, pubsub=WampServerProtocol.SUBSCRIBE) #reactor.callLater(5, self.sendEvent) #def sendEvent(self, event): # self.dispatch("http://example.com/simple", event) if __name__ == '__main__': log.startLogging(sys.stdout) # websocket stuff debug = len(sys.argv) > 1 and sys.argv[1] == 'debug' factory = WampServerFactory("ws://0.0.0.0:9000", debugWamp=debug) factory.protocol = PubSubServer factory.setProtocolOptions(allowHixie76=True) listenWS(factory) # rabbitmq stuff parameters = pika.ConnectionParameters() cc = protocol.ClientCreator(reactor, twisted_connection.TwistedProtocolConnection, parameters) d = cc.connectTCP('localhost', 5672) d.addCallback(lambda protocol: protocol.ready) pika_consumer = PikaConsumer(factory) d.addCallback(pika_consumer.run) reactor.run()
num = decimal.Decimal(arg["num"]) if self.op: if self.op == "+": self.current += num elif self.op == "-": self.current -= num elif self.op == "*": self.current *= num elif self.op == "/": self.current /= num self.op = op else: self.op = op self.current = num res = str(self.current) if op == "=": self.clear() return res if __name__ == '__main__': log.startLogging(sys.stdout) decimal.getcontext().prec = 20 factory = WampServerFactory(debug = False) factory.protocol = CalculatorServerProtocol reactor.listenTCP(9000, factory) reactor.run()
except: print "illegal topic - skipped publication of event" return None class MyServerProtocol(WampServerProtocol): def onConnect(self, connectionRequest): ## register a single, fixed URI as PubSub topic self.registerForPubSub("http://example.com/event/simple") ## 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__': log.startLogging(sys.stdout) factory = WampServerFactory(debug_autobahn = True) factory.protocol = MyServerProtocol reactor.listenTCP(9000, factory) reactor.run()
## register PubSub topics from the auth permissions self.registerForPubSubFromPermissions(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/', [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()
if args.netmask: iplist = args.netmask.split(",") for ip in iplist: if ip.rfind("/") != -1: ip = ip.split("/") ipAllowed = ip[0] mask = ip[1] else: ipAllowed = ip mask = "255.255.255.255" NETMASK.append({ 'ipAllowed': ipV4ToHex(ipAllowed), 'mask': ipV4ToHex(mask) }) uri = "ws://localhost:" + args.port factory = WampServerFactory(uri, debugWamp=args.debug) factory.protocol = CloudeebusServerProtocol factory.setProtocolOptions(allowHixie76=True) # Configure engine for WAMP. engine.factory = factory engine.OPENDOOR = OPENDOOR listenWS(factory) DBusGMainLoop(set_as_default=True) reactor.run()
@exportRpc("asum") def asyncSum(self, list): ## Simulate a slow function. d = defer.Deferred() reactor.callLater(3, d.callback, self.sum(list)) return d class SimpleServerProtocol(WampServerProtocol): """ Demonstrates creating a simple server with Autobahn WebSockets that responds to RPC calls. """ def onSessionOpen(self): # when connection is established, we create our # service instances ... self.calc = Calc() # .. and register them for RPC. that's it. self.registerForRpc(self.calc, "http://example.com/simple/calc#") if __name__ == '__main__': log.startLogging(sys.stdout) factory = WampServerFactory("ws://localhost:9000") factory.protocol = SimpleServerProtocol listenWS(factory) reactor.run()
self.registerForRpc(self.topicservice, "http://%s/%s/" % (app_domain, app_name)) # TODO: Make this part of the custom handler # write a publisher which stores all published RPCs # write a custom subscriber which sends back all published RPCs # write a custom unsubscriber which removes RPCs from the published RPC list # Register a pubsub for clients to exchange information on RPCs they Provide self.registerForPubSub("http://" + app_domain + "/rpc") ### MAIN CODE EXECUTION ### if __name__ == '__main__': log.startLogging(sys.stdout) debug = len(sys.argv) > 1 and sys.argv[1] == 'debug' factory = WampServerFactory("ws://" + ws_host + ":" + ws_port, debugWamp=debug) factory.protocol = PubSubServer1 factory.setProtocolOptions(allowHixie76=True) listenWS(factory) if run_webserver == True: webdir = File(webserver_directory) web = Site(webdir) reactor.listenTCP(webserver_port, web) reactor.run()
from twisted.web.static import File from autobahn.websocket import listenWS from autobahn.wamp import exportRpc, WampServerFactory, WampServerProtocol class MyServerProtocol(WampServerProtocol): @exportRpc def echo(self, msg): return msg def onSessionOpen(self): self.registerForRpc(self, "http://example.com/api#") self.registerForPubSub("http://example.com/event#", True) if __name__ == '__main__': log.startLogging(sys.stdout) factory = WampServerFactory("ws://localhost:9000", debug = False, debugCodePaths = False, debugWamp = True) factory.protocol = MyServerProtocol listenWS(factory) webdir = File(".") webdir.putChild("autobahn.js", File("../../lib/javascript/autobahn.js")) web = Site(webdir) reactor.listenTCP(8080, web) reactor.run()
errs.append(i) if len(errs) > 0: raise Exception("http://example.com/error#invalid_numbers", "one or more numbers are multiples of 3", errs) return reduce(lambda x, y: x + y, list) @exportRpc def sqrt(self, x): return math.sqrt(x) @exportRpc("asum") def asyncSum(self, list): d = defer.Deferred() reactor.callLater(3, d.callback, self.sum(list)) return d class SimpleServerProtocol(WampServerProtocol): def onSessionOpen(self): self.calc = Calc() self.registerForRpc(self.calc, "http://example.com/simple/calc#") if __name__ == '__main__': factory = WampServerFactory("ws://mozart.kawigi.com:9000", debugWamp=True) factory.protocol = SimpleServerProtocol listenWS(factory) reactor.run()
def _listenServer(self, d): factory = WampServerFactory('ws://localhost:9000', debugWamp=True) factory.protocol = ServerProtocol factory.onConnectionLost = d return listenWS(factory)
def reload_instance(self): pass def restart_instance(self): pass def get_option(short_name, long_name=None): return None if __name__ == '__main__': # Load services db = client["stretch-agent"] docker_client = docker.Client(base_url='unix://var/run/docker.sock', version='1.6', timeout=10) # Start supervsior supervisor = InstanceSupervisor(db, docker_client) supervisor.start(get_option('t', 'ttl') or CONFIG_TTL) # Start agent agent = Agent(db, supervisor) port = get_option('p', 'port') or PORT factory = WampServerFactory('ws://localhost:%s' % port, debugWamp=True) factory.protocol = AgentServerProtocol listenWS(factory) reactor.run()