Exemple #1
0
 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)
Exemple #2
0
	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 startFactory(self):
      WampServerFactory.startFactory(self)
      log.msg("AdminWebSocketFactory started [speaking %s]" % self.protocols)

      log.msg("debugWamp: %s" % self.debugWamp)
      log.msg("debugApp: %s" % self.debugApp)

      self.updateAvailable = {"update-available": False}
      self.autocheckForUpdates()
Exemple #4
0
    def startFactory(self):
        WampServerFactory.startFactory(self)
        log.msg("AdminWebSocketFactory started [speaking %s]" % self.protocols)

        log.msg("debugWamp: %s" % self.debugWamp)
        log.msg("debugApp: %s" % self.debugApp)

        self.updateAvailable = {"update-available": False}
        self.autocheckForUpdates()
   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
Exemple #7
0
   def __init__(self, url, dbpool, services):
      WampServerFactory.__init__(self, url, debug = False, debugWamp = False)
      self.dbpool = dbpool
      self.services = services
      self.stats = {'ws-connections': 0,
                    'ws-publications': 0,
                    'ws-dispatched-success': 0,
                    'ws-dispatched-failed': 0}
      self.statsChanged = False

      self.trackingCookies = {}
class WebSocketServer():
    server = None

    def __init__(self, port, debug):
        if debug:
            log.startLogging(sys.stdout)

        self.server = WampServerFactory("ws://localhost:"+ str(port), debug)
        self.server.protocol = LogeeProtocol
        listenWS(self.server)

    def broadcast(self, topic, message):
        self.server.dispatch(topic, message)
Exemple #9
0
   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)

      print "Load/Latency Broker listening on %s [skiputf8validate = %s, allowunmasked = %s]" % (config.wsuri, config.skiputf8validate, config.allowunmasked)
    def __init__(self, port, debug):
        if debug:
            log.startLogging(sys.stdout)

        self.server = WampServerFactory("ws://localhost:"+ str(port), debug)
        self.server.protocol = LogeeProtocol
        listenWS(self.server)
Exemple #11
0
 def dispatch(self, topicUri, event, exclude = [], eligible = None):
    """
    Normal dispatch from a WAMP client publish.
    """
    d = WampServerFactory.dispatch(self, topicUri, event, exclude, eligible)
    d.addCallback(self.logNormalDispatch)
    return d
Exemple #12
0
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)
Exemple #13
0
 def dispatchHubEvent(self, topicuri, event, exclude = [], eligible = None):
    """
    Dispatch from a REST API Push.
    """
    if exclude:
       exclude = self.sessionIdsToProtos(exclude)
    if eligible:
       eligible = self.sessionIdsToProtos(eligible)
    return WampServerFactory.dispatch(self, topicuri, event, exclude, eligible)
Exemple #14
0
   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()
Exemple #15
0
   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()
Exemple #16
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")
Exemple #17
0
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()
Exemple #18
0
 def stopFactory(self):
     log.msg("AdminWebSocketFactory stopped")
     WampServerFactory.stopFactory(self)
Exemple #19
0
      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("ws://localhost:9000")
   factory.protocol = CalculatorServerProtocol
   listenWS(factory)
   reactor.run()
      self.memoryChartSwap.timer.stop()
      self.memoryChartSwap = None

      self.memoryInfoVirt.timer.stop()
      self.memoryInfoVirt = None

      self.memoryInfoSwap.timer.stop()
      self.memoryInfoSwap = None



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://192.168.1.66:9002", debugWamp = debug)
   factory.protocol = MemoryMonitorServerProtocol
   factory.setProtocolOptions(allowHixie76 = True)
   listenWS(factory)

   webdir = File(".")
   web = Site(webdir)
   reactor.listenTCP(8082, web)

   reactor.run()
Exemple #21
0
 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
Exemple #22
0
        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()
Exemple #23
0
 def __init__(self, url):
     WampServerFactory.__init__(self, url)
     self.mcuProtocol = McuProtocol(self)
Exemple #24
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()
Exemple #25
0
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()
Exemple #26
0
 def startFactory(self):
     WampServerFactory.startFactory(self)
     reactor.callLater(5, self.connectGephi)
Exemple #27
0
   """

   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__':

   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)
   listenWS(factory)

   webdir = File(".")
   web = Site(webdir)
   reactor.listenTCP(8080, web)

   reactor.run()
Exemple #28
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()
Exemple #29
0
 def startFactory(self):
    WampServerFactory.startFactory(self)
    self.setOptionsFromConfig()
    log.msg("HubWebSocketFactory started [speaking %s, %s]" % (self.protocols, self.versions))
    self.publishStats()
Exemple #30
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
      ##
      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()
   def __init__(self, url):
      WampServerFactory.__init__(self, url)

      ## the key-value store resides on the factory object, since it is to
      ## be shared among all client connections
      self.keyvalue = KeyValue("keyvalue.dat")
                return None
        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()
Exemple #33
0
    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()
Exemple #34
0
from twisted.web.static import File

from autobahn.twisted.websocket import listenWS
from autobahn.wamp 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()
Exemple #35
0
 def __init__(self, url, debugWamp=False):
     WampServerFactory.__init__(self, url, debugWamp=debugWamp)
     self.clients = []
Exemple #36
0
 def onClientUnsubscribed(self, *a, **k):
    WampServerFactory.onClientUnsubscribed(self, a, k)
    print '< client unsubscribed'
    self.printSubscriptions()
Exemple #37
0
from autobahn.wamp import WampServerFactory, \
                          WampServerProtocol


class PubSubServer1(WampServerProtocol):

   def onSessionOpen(self):

      ## register a single, fixed URI as PubSub topic
      self.registerForPubSub("http://example.com/simple")

      ## register a URI and all URIs having the string as prefix as PubSub topic
      self.registerForPubSub("http://example.com/event#", 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 = PubSubServer1
   factory.setProtocolOptions(allowHixie76 = True)
   listenWS(factory)

   webdir = File(".")
   web = Site(webdir)
   reactor.listenTCP(8080, web)

   reactor.run()
Exemple #38
0
 def __init__(self, url, debugWamp, timeout):
     self._reaper = None
     self._connection_count = 0
     self._timeout = timeout
     WampServerFactory.__init__(self, url, debugWamp)
Exemple #39
0
 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)
Exemple #40
0
 def startFactory(self):
     if not self._reaper:
         self._reaper = reactor.callLater(self._timeout,
                                          lambda: reactor.stop())
     WampServerFactory.startFactory(self)
Exemple #41
0
   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()
Exemple #42
0
    @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()
#!/usr/bin/env python2.7 -u -Wall

import sys

from twisted.internet import reactor
from twisted.python import log
from autobahn.wamp import WampServerFactory, \
                          WampServerProtocol, \
                          exportRpc
from autobahn.websocket import listenWS

class RpcServerProtocol(WampServerProtocol):

   @exportRpc
   def add(self, x, y):
      return x + y

   def onSessionOpen(self):
      self.registerForPubSub("/mpd/test")

if __name__ == '__main__':
   factory = WampServerFactory("ws://localhost:9001", debug=True)
   factory.protocol = WampServerProtocol
   log.startLogging(sys.stdout)
   listenWS(factory)
   print "Here we go"
   sys.stdout.flush() # flush the line so that tests know we're up
   sys.stderr.flush()
   reactor.run()
Exemple #44
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()
 def __init__(self, url, dbpool, services):
    WampServerFactory.__init__(self, url, debugApp = False)
    self.dbpool = dbpool
    self.services = services
    self.restartRequired = False
 def __init__(self, url, debugWamp, timeout):
     self._reaper = None
     self._connection_count = 0
     self._timeout = timeout
     WampServerFactory.__init__(self, url, debugWamp)
 def stopFactory(self):
    log.msg("AdminWebSocketFactory stopped")
    WampServerFactory.stopFactory(self)
 def startFactory(self):
     if not self._reaper:
         self._reaper = reactor.callLater(self._timeout, lambda: reactor.stop())
     WampServerFactory.startFactory(self)