예제 #1
0
    def startService(self):

        factory = WebSocketServerFactory("ws://127.0.0.1:%d" % self.port)
        factory.protocol = EchoServerProtocol

        # FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
        factory.startFactory()

        resource = WebSocketResource(factory)

        # we server static files under "/" ..
        webdir = os.path.abspath(pkg_resources.resource_filename("echows", "web"))
        root = File(webdir)

        # and our WebSocket server under "/ws" (note that Twisted uses
        # bytes for URIs)
        root.putChild(b"ws", resource)

        # both under one Twisted Web Site
        site = Site(root)

        self.site = site
        self.factory = factory

        self.listener = reactor.listenTCP(self.port, site)
예제 #2
0
    def startService(self):

        factory = WebSocketServerFactory("ws://localhost:%d" % self.port,
                                         debug=self.debug)

        factory.protocol = EchoServerProtocol
        factory.setProtocolOptions(
            allowHixie76=True)  # needed if Hixie76 is to be supported

        # FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
        factory.startFactory()

        resource = WebSocketResource(factory)

        # we server static files under "/" ..
        webdir = os.path.abspath(
            pkg_resources.resource_filename("echows", "web"))
        root = File(webdir)

        # and our WebSocket server under "/ws"
        root.putChild("ws", resource)

        # both under one Twisted Web Site
        site = Site(root)
        site.protocol = HTTPChannelHixie76Aware  # needed if Hixie76 is to be supported

        self.site = site
        self.factory = factory

        self.listener = reactor.listenTCP(self.port, site)
예제 #3
0
파일: saged.py 프로젝트: lowgoz/dockergate
def boot(listen_addr='127.0.0.1',
         port=8080,
         session_bus=False,
         sage_www_root=DEFAULT_SAGE_ROOT,
         auth_realm=None,
         auth_passwd=None,
         allow_ga=None,
         deny_ga=None,
         no_www=False):

    assert not (
        allow_ga and deny_ga
    ), 'Must not specify both deny and allow rules for group addresses'
    global api
    global factory
    DBusGMainLoop(set_as_default=True)

    if session_bus:
        bus = dbus.SessionBus()
    else:
        bus = dbus.SystemBus()

    obj = bus.get_object(DBUS_SERVICE, DBUS_PATH)
    api = dbus.Interface(obj, DBUS_INTERFACE)

    uri = createWsUrl(listen_addr, port)
    factory = SageProtocolFactory(uri,
                                  debug=False,
                                  api=api,
                                  allow_ga=allow_ga,
                                  deny_ga=deny_ga)
    factory.setProtocolOptions(allowHixie76=True, webStatus=False)
    factory.protocol = SageProtocol
    factory.clients = []

    resource = WebSocketResource(factory)

    if no_www:
        root = resource
    else:
        root = File(sage_www_root)
        root.putChild('saged', resource)

    if auth_realm != None and auth_passwd != None:
        portal = Portal(SageRealm(root), [ApachePasswordDB(auth_passwd)])
        credentialFactories = [
            BasicCredentialFactory(auth_realm),
        ]
        root = HTTPAuthSessionWrapper(portal, credentialFactories)

    site = Site(root)
    site.protocol = HTTPChannelHixie76Aware
    reactor.listenTCP(port, site, interface=listen_addr)

    reactor.run()
예제 #4
0
def start_webserver(options,
                    protocol=paraviewweb_wamp.ServerProtocol,
                    disableLogging=False):
    """
    Starts the web-server with the given protocol. Options must be an object
    with the following members:
        options.port : port number for the web-server to listen on
        options.timeout : timeout for reaping process on idle in seconds
        options.content : root for web-pages to serve.
    """
    from twisted.internet import reactor
    from twisted.web.server import Site
    from twisted.web.static import File
    import sys

    if not disableLogging:
        log.startLogging(sys.stdout)

    # setup the server-factory
    wampFactory = paraviewweb_wamp.ReapingWampServerFactory(
        "ws://localhost:%d" % options.port, options.debug, options.timeout)
    wampFactory.protocol = protocol

    # Do we serve static content or just websocket ?
    if len(options.content) == 0:
        # Only WebSocket
        listenWS(wampFactory)
    else:
        # Static HTTP + WebSocket
        wsResource = WebSocketResource(wampFactory)

        root = File(options.content)
        root.putChild("ws", wsResource)

        webgl = WebGLResource()
        root.putChild("WebGL", webgl)

        site = Site(root)

        reactor.listenTCP(options.port, site)

    # Start factory and reactor
    wampFactory.startFactory()
    if options.nosignalhandlers:
        reactor.run(installSignalHandlers=0)
    else:
        reactor.run()
    wampFactory.stopFactory()
예제 #5
0
def startServer(options, disableLogging=False):
    """
  Starts the web server. Options must be an object with the following members:
    options.port : port number on which the server will listen
    options.timeout : timeout (seconds) for reaping process on idle
    options.content : root path of common content to serve
    options.app_content : root path of application-specific content to serve
  """
    from twisted.python import log
    from twisted.internet import reactor
    from twisted.web.server import Site
    from twisted.web.static import File

    from autobahn.resource import WebSocketResource
    from paraview.webgl import WebGLResource

    if options.content is None and options.app_content is None:
        raise EnvironmentError(0, 'No content specified')

    if not disableLogging:
        log.startLogging(sys.stdout)

    # Set up the server factory
    wampFactory = paraviewweb_wamp.ReapingWampServerFactory(
        "ws://localhost:%d" % options.port, options.debug, options.timeout)
    wampFactory.protocol = WebProtocol

    # Set up the site
    root = None
    if options.app_content is None:
        root = File(options.content)
    elif options.content is None:
        root = File(options.app_content)
    else:
        root = File(options.content)
        root.putChild("app", File(options.app_content))

    root.putChild("ws", WebSocketResource(wampFactory))
    root.putChild("WebGL", WebGLResource())

    # Start factory and reactor
    wampFactory.startFactory()
    reactor.listenTCP(options.port, Site(root))
    reactor.run()
    wampFactory.stopFactory()
예제 #6
0
    app.debug = debug
    if debug:
        log.startLogging(sys.stdout)

    ##
    ## create a Twisted Web resource for our WebSocket server
    ##
    wsFactory = WebSocketServerFactory("ws://localhost:8080",
                                       debug=debug,
                                       debugCodePaths=debug)

    wsFactory.protocol = EchoServerProtocol
    wsFactory.setProtocolOptions(
        allowHixie76=True)  # needed if Hixie76 is to be supported

    wsResource = WebSocketResource(wsFactory)

    ##
    ## create a Twisted Web WSGI resource for our Flask server
    ##
    wsgiResource = WSGIResource(reactor, reactor.getThreadPool(), app)

    ##
    ## create a root resource serving everything via WSGI/Flask, but
    ## the path "/ws" served by our WebSocket stuff
    ##
    rootResource = WSGIRootResource(wsgiResource, {'ws': wsResource})

    ##
    ## create a Twisted Web Site and run everything
    ##
예제 #7
0
def start_webserver(options, protocol=wamp.ServerProtocol, disableLogging=False):
    """
    Starts the web-server with the given protocol. Options must be an object
    with the following members:
        options.host : the interface for the web-server to listen on
        options.port : port number for the web-server to listen on
        options.timeout : timeout for reaping process on idle in seconds
        options.content : root for web-pages to serve.
    """
    from twisted.internet import reactor
    from twisted.web.server import Site
    from twisted.web.static import File
    import sys

    if not disableLogging:
        log.startLogging(sys.stdout)

    contextFactory = None

    use_SSL = False
    if options.sslKey and options.sslCert:
      use_SSL = True
      wsProtocol = "wss"
      from twisted.internet import ssl
      contextFactory = ssl.DefaultOpenSSLContextFactory(
        options.sslKey, options.sslCert)
    else:
      wsProtocol = "ws"

    # setup the server-factory
    wampFactory = wamp.ReapingWampServerFactory(
        "%s://%s:%d" % (wsProtocol, options.host, options.port), options.debug, options.timeout)
    wampFactory.protocol = protocol

    # Do we serve static content or just websocket ?
    if len(options.content) == 0:
        # Only WebSocket
        listenWS(wampFactory, contextFactory)
    else:
        # Static HTTP + WebSocket
        wsResource = WebSocketResource(wampFactory)

        root = File(options.content)
        root.putChild("ws", wsResource)

        if options.uploadPath != None :
            from upload import UploadPage
            uploadResource = UploadPage(options.uploadPath)
            root.putChild("upload", uploadResource)

        site = Site(root)

        if use_SSL:
          reactor.listenSSL(options.port, site, contextFactory)
        else:
          reactor.listenTCP(options.port, site)

    # Work around to force the output buffer to be flushed
    # This allow the process launcher to parse the output and
    # wait for "Start factory" to know that the WebServer
    # is running.
    if options.forceFlush :
        for i in range(200):
            log.msg("+"*80, logLevel=logging.CRITICAL)

    # Give test client a chance to initialize a thread for itself
    # testing.initialize(opts=options)

    # Start the factory
    wampFactory.startFactory()

    # Initialize testing: checks if we're doing a test and sets it up
    testing.initialize(options, reactor)

    # Start the reactor
    if options.nosignalhandlers:
        reactor.run(installSignalHandlers=0)
    else:
        reactor.run()

    # Stope the factory
    wampFactory.stopFactory()

    # Give the testing module a chance to finalize, if necessary
    testing.finalize()
예제 #8
0
        #fin = open("/home/dhan/projects/flask-slideatlas/data/tiger.jpg")
        self.sendMessage(fin.read(), True)

if __name__ == '__main__':

    if len(sys.argv) > 1 and sys.argv[1] == 'debug':
       log.startLogging(sys.stdout)
       debug = True
    else:
       debug = False

    factory = WebSocketServerFactory("ws://localhost:8000",
                                     debug = debug,
                                     debugCodePaths = debug)

    factory.protocol = EchoServerProtocol
    factory.setProtocolOptions(allowHixie76 = True) # needed if Hixie76 is to be supported

    # Mount different resources

    wsRes = WebSocketResource(factory)

    wsgiRes = WSGIResource(reactor, reactor.getThreadPool(), app)

    rootRes = WSGIRootResource(wsgiRes, {'ws' : wsRes})

    site = Site(rootRes)

    reactor.listenTCP(8000, site )
    reactor.run()
예제 #9
0
if __name__ == '__main__':

    if len(sys.argv) > 1 and sys.argv[1] == 'debug':
        log.startLogging(sys.stdout)
        debug = True
    else:
        debug = False

    factory = WebSocketServerFactory("ws://localhost:8080",
                                     debug=debug,
                                     debugCodePaths=debug)

    factory.protocol = EchoServerProtocol
    factory.setProtocolOptions(
        allowHixie76=True)  # needed if Hixie76 is to be supported

    resource = WebSocketResource(factory)

    ## we server static files under "/" ..
    root = File(".")

    ## and our WebSocket server under "/ws"
    root.putChild("ws", resource)

    ## both under one Twisted Web Site
    site = Site(root)
    site.protocol = HTTPChannelHixie76Aware  # needed if Hixie76 is to be supported
    reactor.listenTCP(8080, site)

    reactor.run()
예제 #10
0
        self.sendMessage("Echo 2 - " + msg)


if __name__ == '__main__':

    if len(sys.argv) > 1 and sys.argv[1] == 'debug':
        log.startLogging(sys.stdout)
        debug = True
    else:
        debug = False

    factory1 = WebSocketServerFactory("ws://localhost:9000",
                                      debug=debug,
                                      debugCodePaths=debug)
    factory1.protocol = Echo1ServerProtocol
    resource1 = WebSocketResource(factory1)

    factory2 = WebSocketServerFactory("ws://localhost:9000",
                                      debug=debug,
                                      debugCodePaths=debug)
    factory2.protocol = Echo2ServerProtocol
    resource2 = WebSocketResource(factory2)

    ## Establish a dummy root resource
    root = Data("", "text/plain")

    ## and our WebSocket servers under different paths ..
    root.putChild("echo1", resource1)
    root.putChild("echo2", resource2)

    ## both under one Twisted Web Site
예제 #11
0
      db.session.commit()
   except IntegrityError:
      return "IntegrityError"
   except:return "ServerError"
   return "true"
@app.route('/scriptcam.lic')
def static_from_root():
   return redirect('/static/ScriptCam/scriptcam.lic')

##
## create a Twisted Web resource for our WebSocket server
##
msgFactory = WebSocketServerFactory(IP,debug = debug,debugCodePaths = debug)
msgFactory.protocol = MsgServerProtocol
msgFactory.setProtocolOptions(allowHixie76 = True) # needed if Hixie76 is to be supported
msgResource = WebSocketResource(msgFactory)

imgFactory = WebSocketServerFactory(IP,debug = debug,debugCodePaths = debug)
imgFactory.protocol = ImgServerProtocol
imgFactory.setProtocolOptions(allowHixie76 = True) # needed if Hixie76 is to be supported
imgResource = WebSocketResource(imgFactory)

##
## create a Twisted Web WSGI resource for our Flask server
##
wsgiResource = WSGIResource(reactor, reactor.getThreadPool(), app)

##
## create a root resource serving everything via WSGI/Flask, but
## the path "/ws" served by our WebSocket stuff
##