Example #1
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
Example #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
Example #3
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)
Example #4
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")
Example #5
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")
Example #6
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()
Example #7
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()
#!/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()
Example #9
0
    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()
    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 onConnect(self, connectionRequest):

        # when a client connects, we can check if we
        # want to accept here, and if so, we create
        # instances of our service classes ..
        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(debug=False)
    factory.protocol = SimpleServerProtocol
    reactor.listenTCP(9000, factory)
    reactor.run()
Example #11
0
    @exportRpc("state")
    def state(self):
        return running

if PI:
    def cleanup():
        GPIO.output(12, False)
        GPIO.cleanup()

    atexit.register(cleanup)

if __name__ == '__main__':
#    if len(sys.argv) > 1 and sys.argv[1] == 'debug':
#        log.startLogging(sys.stdout)
#        debug = True
#    else:
#        debug = False
    
    log.startLogging(sys.stdout)
    
    factory = WampServerFactory("ws://localhost:9000", debugWamp=True)
    factory.protocol = ScarefrogServerProtocol
    factory.setProtocolOptions(allowHixie76=True)
    listenWS(factory)
    
    webdir = File("www")
    web = Site(webdir)
    reactor.listenTCP(8080, web)

    reactor.run()
Example #12
0
from twisted.web.server import Site
from twisted.web.static import File

from autobahn.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()
Example #13
0
    def connectionLost(self, reason):
        """
      When connection is gone (i.e. client close window, navigated
      away from the page), stop the model timer, which holds last
      reference to model, and delete the model
      """
        WampServerProtocol.connectionLost(self, reason)

        # self.logModel.timer.stop()
        self.logModel = 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://localhost:9005", debugWamp=debug)
    factory.protocol = LogMonitorServerProtocol
    factory.setProtocolOptions(allowHixie76=True)
    listenWS(factory)

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

    reactor.run()
Example #14
0
        if sx > bx:
            scale_factor = bx/float(ix)
            sx = bx
            sy = scale_factor * iy
        else:
            sy = by

    return pygame.transform.smoothscale(img, (int(sx),int(sy)))

# log.startLogging(sys.stdout)
log.startLogging(open('log.txt','w'))
print "Darrell's toy photo frame"

#  Setup RPC
factory = WampServerFactory("ws://localhost:9000")
factory.protocol = RpcServerProtocol
listenWS(factory)

# Initial pygame and the screen 
pygame.init()
w = pygame.display.Info().current_w
h= pygame.display.Info().current_h
print "w: ", w, "h: ", h
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
pygame.mouse.set_visible(0)
screen = pygame.display.set_mode(size,pygame.FULLSCREEN)

# Create and Fill background
background = pygame.Surface(screen.get_size())
background = background.convert()  # This is cargo cult.. I don't know why it's here.
background.fill(bgcolor)
Example #15
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()
Example #16
0
        self.registerForPubSub(_url('players'))
        
        self.pubsub = PubSubHandlers(self)
        self.registerHandlerForPubSub(self.pubsub, BASE_URL)

    def connectionLost(self, reason):
        self.pubsub.send_users_list(exclude=[self])
        WampServerProtocol.connectionLost(self, reason)


class EatBulletServerFactory(WampServerFactory):

    def __init__(self, url, debug=False, debugCodePaths=False, debugWamp=False, debugApp=False, externalPort=None):
        self.games = []
        WampServerFactory.__init__(self, url, debug=debug, debugCodePaths=debugCodePaths, externalPort=externalPort)


if __name__ == '__main__':

    log.startLogging(sys.stdout)
    
    factory = WampServerFactory('ws://localhost:9000', debugWamp=True)
    factory.protocol = EatBulletServerProtocol
    listenWS(factory)

    webdir = File(".")
    web = Site(webdir)
    reactor.listenTCP(8080, web)
    
    reactor.run()
			req = urllib2.Request(auxUrl)
			response = urllib2.urlopen(req)
			response1 = response.read()
			return json.loads(response1)
		except KeyError:
			return {"error" : "Key don't exist in Json"}





class WampServerFilper(WampServerProtocol):
 
   def onSessionOpen(self):
      self.notifications = notifications()
      self.registerForRpc(self.notifications, "http://filper.com/rpc/notifications#")
      self.registerForPubSub("http://filper.com/pubSub/notifications#", True)

 
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 = WampServerFilper
	listenWS(factory)
	reactor.run()
try:
    os.makedirs(os.path.dirname(CACHE_FILE))
except exceptions.OSError, e:
    if e.errno != 17:
        log.err()
try:
    os.makedirs(os.path.dirname(LOG_FILE))
except exceptions.OSError, e:
    if e.errno != 17:
        log.err()

# TODO refactor: use util method in ws lib for url creation
host = socket.gethostbyaddr(socket.gethostname())[0]
uri = "ws://%s:%s/" % (host, WS_PORT)
factory = WampServerFactory(uri, debugWamp=False)
factory.protocol = yadtbroadcastserver.BroadcastServerProtocol
yadtbroadcastserver.BroadcastServerProtocol.init_cache()
yadtbroadcastserver.BroadcastServerProtocol.reset_metrics_at_midnight(first_call=True)
yadtbroadcastserver.BroadcastServerProtocol.schedule_write_metrics(first_call=True)
reactor.listenTCP(WS_PORT, factory)
log.msg("ws listens on port %s" % WS_PORT)

docroot = static.File(DOCROOT_DIR)


class YadtApi(Resource):
    isLeaf = True

    KNOWN_APIS = set(["yadt"])
    KNOWN_COMMANDS = set(["status"])
Example #19
0
 def _listenServer(self, d):
     factory = WampServerFactory('ws://localhost:9000', debugWamp=True)
     factory.protocol = ServerProtocol
     factory.onConnectionLost = d
     return listenWS(factory)
Example #20
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 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()
Example #21
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()
Example #22
0
        return threads.deferToThread( thunk )

    def onAuthenticated( self, authKey, perms ):
        peer = self.peerstr
        if authKey is None:
            msg = "Anonymous connected from %s" % peer
        else:
            msg = "%s connected from %s" % (authKey,peer)
        self.currentUser = authKey
        self.currentRole = 'default'
        deferLater( reactor, 1, lambda: NotificationProtocol.notify(msg) )



f = WampServerFactory( "ws://localhost:2001", debugWamp=True )
f.protocol = WorkflowProtocol
#
# allowHixie76=True is required in order to work with iOS and Safari,
# but this is insecure
#
# see https://groups.google.com/forum/?fromgroups=#!topic/autobahnws/wOEU3Bvp4HQ

f.setProtocolOptions( allowHixie76=True )
listenWS(f)
NotificationProtocol.start()

from twisted.python import log

reactor.listenTCP( 2000, Site( root ) )
import sys
log.startLogging( sys.stdout )
Example #23
0
   def connectionLost(self, reason):
      """
      When connection is gone (i.e. client close window, navigated
      away from the page), stop the model timer, which holds last
      reference to model, and delete the model
      """
      WampServerProtocol.connectionLost(self, reason)

      self.processModel.timer.stop()
      self.processModel = 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://localhost:9001", debugWamp = debug)
   factory.protocol = ProcessMonitorServerProtocol
   factory.setProtocolOptions(allowHixie76 = True)
   listenWS(factory)

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

   reactor.run()
Example #24
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 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()
Example #25
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()
Example #26
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()
Example #27
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()
Example #28
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()
Example #29
0
      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()
      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()
    """
   A minimalistic RPC server.
   """
    def onSessionOpen(self):
        # When the WAMP session has been established, register any methods
        # remoted on this class for RPC
        self.registerForRpc(self, "http://example.com/simple/calc#")

    @exportRpc("add")
    def add(self, x, y):
        """
      A simple remoted method which can be called via RPC from any WAMP client.
      """
        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://0.0.0.0:9000", debugWamp=debug)
    factory.protocol = RpcServer1Protocol
    factory.setProtocolOptions(allowHixie76=True)
    listenWS(factory)

    reactor.run()
Example #32
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()
Example #33
0
    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()
            values = event
            encode = urllib.urlencode(values)
            auxUrl = url + '?' + encode
            req = urllib2.Request(auxUrl)
            response = urllib2.urlopen(req)
            response1 = response.read()
            return json.loads(response1)
        except KeyError:
            return {"error": "Key don't exist in Json"}


class WampServerFilper(WampServerProtocol):
    def onSessionOpen(self):
        self.notifications = notifications()
        self.registerForRpc(self.notifications,
                            "http://filper.com/rpc/notifications#")
        self.registerForPubSub("http://filper.com/pubSub/notifications#", True)


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 = WampServerFilper
    listenWS(factory)
    reactor.run()
Example #35
0
	  self.publish("http://skycaptains.com/event#" + game_id, {"to": "client",
	    "type": "game over", "winner": self.games[game_id].get_winner()})
	  #Delete game from games
	  del self.games[game_id]

#SkyCaptains Server
class SkyCaptainsServer(WampServerProtocol):

  def onSessionOpen(self):
    #Init game
    self.registerForPubSub("http://skycaptains.com/game")
    #Game events
    self.registerForPubSub("http://skycaptains.com/event#", True)
    #Chat
    self.registerForPubSub("http://skycaptains.com/chat")


if __name__ == "__main__":
  url = "ws://" + os.environ["SKYCAPTAINS_SERVER"] + ":" + os.environ["SKYCAPTAINS_PORT"]
  factory = WampServerFactory(url, debugWamp = False)
  factory.protocol = SkyCaptainsServer
  factory.setProtocolOptions(allowHixie76 = True)
  listenWS(factory)

  factory = WampClientFactory(url, debugWamp = False)
  factory.protocol = SkyCaptainsClient
  connectWS(factory)

  reactor.run()

Example #36
0
class DeviceStatusProtocol(WampServerProtocol):
    def onSessionOpen(self):
        self.registerDeviceChannels()
        self.registerDeviceGraph()

    def registerDeviceChannels(self):
        self.registerForPubSub(ATTACH)
        self.registerForPubSub(DETACH)
        self.registerForPubSub(UPDATE)

    def registerDeviceGraph(self):
        self.deviceGraph = DeviceGraph(self)
        self.registerForRpc(self.deviceGraph, 'http://mand3l.com/devices#')


if __name__ == '__main__':

    log.startLogging(sys.stdout)
    debug = len(sys.argv) > 1 and sys.argv[1] == 'debug'

    factory = WampServerFactory("ws://0.0.0.0:9000", debugWamp=debug)
    factory.protocol = DeviceStatusProtocol
    factory.setProtocolOptions(allowHixie76=True)
    listenWS(factory)

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

    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()
        jfile.close()
    
    if args.whitelist:
        jfile = open(args.whitelist)
        WHITELIST = json.load(jfile)
        jfile.close()
        
    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)
    
    listenWS(factory)
    
    DBusGMainLoop(set_as_default=True)
    
    reactor.run()
Example #39
0
        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()
Example #40
0
   @exportRpc
   def getIfaces(self):
      """
      Return names of all available network interfaces
      """
      ifaces = psutil.network_io_counters(pernic=True).keys()
      ifaces.append('total')

      return ifaces


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:9004", debugWamp = debug)
   factory.protocol = NetworkInfoServerProtocol
   factory.setProtocolOptions(allowHixie76 = True)
   listenWS(factory)

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

   reactor.run()
                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()
Example #42
0
   def connectionLost(self, reason):
      """
      When connection is gone (i.e. client close window, navigated
      away from the page), stop the model timer, which holds last
      reference to model, and delete the model
      """
      WampServerProtocol.connectionLost(self, reason)
      self.infoModel = 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://localhost:9000", debugWamp = debug)
   factory.protocol = SystemInfoServerProtocol
   factory.setProtocolOptions(allowHixie76 = True)
   listenWS(factory)

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

   reactor.run()
Example #43
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()
Example #44
0
    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()