예제 #1
0
    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) 
예제 #2
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()
예제 #3
0
        """
      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()
예제 #4
0
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()
예제 #5
0
   @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()
예제 #6
0
            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,
예제 #7
0
      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()
예제 #8
0
    """
   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()
예제 #9
0
      ## 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()
예제 #10
0
        ## 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()
예제 #11
0
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()
예제 #12
0
      ## 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()
예제 #13
0
        ## 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()
예제 #14
0
            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()
예제 #15
0
파일: server2.py 프로젝트: si618/pi-time
      ## 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()
예제 #16
0
         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()