Python geventwebsocket.handler.WebSocketHandler() Examples

The following are 13 code examples of geventwebsocket.handler.WebSocketHandler(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module geventwebsocket.handler , or try the search function .
Example #1
Source File: weblcds.py    From artisan with GNU General Public License v3.0 6 votes vote down vote up
def work(p,rp,nonesym,timec,timebg,btc,btbg,etc,etbg,showetflag,showbtflag):
    global port, static_path, nonesymbol, timecolor, timebackground, btcolor, btbackground, etcolor, etbackground, showbt, showet
    port = p
    static_path = rp
    nonesymbol = nonesym
    timecolor = timec
    timebackground = timebg
    btcolor = btc
    btbackground = btbg
    etcolor = etc
    etbackground = etbg
    showet = showetflag
    showbt = showbtflag
    TEMPLATE_PATH.insert(0,rp)
    s = WSGIServer(("0.0.0.0", p), default_app(), handler_class=WebSocketHandler)
    s.serve_forever() 
Example #2
Source File: websocket.py    From pypkjs with MIT License 6 votes vote down vote up
def run(self):
        pebble_greenlet = self.pebble.connect()
        self.pebble.pebble.register_raw_inbound_handler(self._handle_inbound)
        self.pebble.pebble.register_raw_outbound_handler(self._handle_outbound)
        if self.pebble.timeline_is_supported:
            self.timeline.continuous_sync()
            self.timeline.do_maintenance()
        logging.getLogger().addHandler(WebsocketLogHandler(self, level=logging.WARNING))
        if self.ssl_root is not None:
            ssl_args = {
                'keyfile': '%s/server-key.pem' % self.ssl_root,
                'certfile': '%s/server-cert.pem' % self.ssl_root,
                'ca_certs': '%s/ca-cert.pem' % self.ssl_root,
                'ssl_version': ssl.PROTOCOL_TLSv1,
            }
        else:
            ssl_args = {}
        self.server = pywsgi.WSGIServer(("", self.port), self.handle_ws, handler_class=WebSocketHandler, **ssl_args)
        gevent.spawn(self.server.serve_forever)
        pebble_greenlet.join()
        self.server.close()
        self.pebble.disconnect() 
Example #3
Source File: server.py    From cascade-server with Apache License 2.0 5 votes vote down vote up
def configure_flask_logger():
    """
    Unfortunately there is a known issue using geventwebsocket.WebSocketHandler
    and the core logging module. This is a hack to still be able to see the flask logs.
    http://www.gevent.org/gevent.pywsgi.html#gevent.pywsgi.LoggingLogAdapter
    """
    flask_logger = logging.getLogger()
    flask_ch = logging.StreamHandler()
    flask_logger.setLevel(logging.INFO)
    flask_logger.addHandler(flask_ch)
    return flask_logger 
Example #4
Source File: server.py    From cascade-server with Apache License 2.0 5 votes vote down vote up
def run_server(debug=False):
    global app

    config = settings.load()
    attack.attack_url = config['links']['attack']
    attack.proxies = config['links']['proxies']

    interface = config['server']['interface']
    port = config['server']['port']
    threaded = True if debug else not async.enable_async()

    flask_logger = configure_flask_logger()
    connect_to_database()

    # if not threaded and not debug:
    ssl_context = {}
    https = config['server']['https']
    if https['enabled']:
        ssl_context['certfile'] = https['certfile']
        ssl_context['keyfile'] = https['keyfile']

    app.debug = debug

    print('Running CASCADE via WSGIServer on {url}'.format(url=config['server']['url']))
    wsgi = WSGIServer((interface, port), app, log=flask_logger, handler_class=WebSocketHandler, **ssl_context)
    wsgi.serve_forever() 
Example #5
Source File: __init__.py    From OpenMTC with Eclipse Public License 1.0 5 votes vote down vote up
def _get_server(self):
        return WSGIServer((self.listen_on, self.port),
                          SioMiddleware(self.sio_app, self.flask_app),
                          handler_class=WebSocketHandler) 
Example #6
Source File: wsgi.py    From python-getting-started with MIT License 5 votes vote down vote up
def run():
        global application
        app.debug = True
        application = DebuggedApplication(application, evalex=True)
        server = WSGIServer(('localhost', PORT), application, handler_class=WebSocketHandler)
        server.serve_forever() 
Example #7
Source File: client.py    From qdb with Apache License 2.0 5 votes vote down vote up
def __init__(self,
                 session_store,
                 host='localhost',
                 port=8002,
                 route=DEFAULT_ROUTE,
                 auth_fn=None,
                 auth_timeout=60):  # seconds
        """
        The parameters here are the same  for the client server except for
        route, where route is a regular expression (as a string or regex
        object) that defines where to look for connections.
        For example:
            `/(.+)`
        There should be exactly one group in the route, this will be the uuid
        match.
        The auth_timeout is the amount of time to leave a socket open awaiting
        the start_event or first message. This is measured in seconds.
        """
        self.auth_fn = auth_fn or self.NO_AUTH
        self.auth_timeout = auth_timeout
        self.route = re.compile(route, re.IGNORECASE)
        self.session_store = session_store
        if self.route.groups != 1:
            # We need exactly one regex group.
            raise QdbInvalidRoute(self.route)
        self._server = pywsgi.WSGIServer(
            (host, port),
            self.handle_client,
            handler_class=WebSocketHandler,
        ) 
Example #8
Source File: cli.py    From dagster with Apache License 2.0 5 votes vote down vote up
def start_server(host, port, app, port_lookup, port_lookup_attempts=0):
    server = pywsgi.WSGIServer((host, port), app, handler_class=WebSocketHandler)

    print(
        'Serving on http://{host}:{port} in process {pid}'.format(
            host=host, port=port, pid=os.getpid()
        )
    )

    log_action(START_DAGIT_WEBSERVER)
    with uploading_logging_thread():
        try:
            server.serve_forever()
        except OSError as os_error:
            if 'Address already in use' in str(os_error):
                if port_lookup and (
                    port_lookup_attempts > 0
                    or click.confirm(
                        (
                            'Another process on your machine is already listening on port {port}. '
                            'Would you like to run the app at another port instead?'
                        ).format(port=port)
                    )
                ):
                    port_lookup_attempts += 1
                    start_server(host, port + port_lookup_attempts, app, True, port_lookup_attempts)
                else:
                    six.raise_from(
                        Exception(
                            (
                                'Another process on your machine is already listening on port {port}. '
                                'It is possible that you have another instance of dagit '
                                'running somewhere using the same port. Or it could be another '
                                'random process. Either kill that process or use the -p option to '
                                'select another port.'
                            ).format(port=port)
                        ),
                        os_error,
                    )
            else:
                raise os_error 
Example #9
Source File: server.py    From youtube-dl-nas with MIT License 5 votes vote down vote up
def run(self, handler):
        server = pywsgi.WSGIServer((self.host, self.port), handler, handler_class=WebSocketHandler)

        if not self.quiet:
            server.logger = create_logger('geventwebsocket.logging')
            server.logger.setLevel(logging.INFO)
            server.logger.addHandler(logging.StreamHandler())

        server.serve_forever() 
Example #10
Source File: runserver.py    From python-socketio with MIT License 5 votes vote down vote up
def handle(self, *args, **options):
        if sio.async_mode == 'threading':
            super(Command, self).handle(*args, **options)
        elif sio.async_mode == 'eventlet':
            # deploy with eventlet
            import eventlet
            import eventlet.wsgi
            from django_example.wsgi import application
            eventlet.wsgi.server(eventlet.listen(('', 8000)), application)
        elif sio.async_mode == 'gevent':
            # deploy with gevent
            from gevent import pywsgi
            from django_example.wsgi import application
            try:
                from geventwebsocket.handler import WebSocketHandler
                websocket = True
            except ImportError:
                websocket = False
            if websocket:
                pywsgi.WSGIServer(
                    ('', 8000), application,
                    handler_class=WebSocketHandler).serve_forever()
            else:
                pywsgi.WSGIServer(('', 8000), application).serve_forever()
        elif sio.async_mode == 'gevent_uwsgi':
            print('Start the application through the uwsgi server. Example:')
            print('uwsgi --http :5000 --gevent 1000 --http-websockets '
                  '--master --wsgi-file django_example/wsgi.py --callable '
                  'application')
        else:
            print('Unknown async_mode: ' + sio.async_mode) 
Example #11
Source File: server.py    From NSC_BUILDER with MIT License 5 votes vote down vote up
def run(self, handler):
        server = pywsgi.WSGIServer((self.host, self.port), handler, handler_class=WebSocketHandler, **self.options)

        if not self.quiet:
            server.logger = create_logger('geventwebsocket.logging')
            server.logger.setLevel(logging.INFO)
            server.logger.addHandler(logging.StreamHandler())

        server.serve_forever() 
Example #12
Source File: manage.py    From mining with MIT License 5 votes vote down vote up
def runserver(port, ip, debug):

    if debug is None:
        server = WSGIServer((ip, port), app, handler_class=WebSocketHandler)
        server.serve_forever()

    click.echo(u'OpenMining start server at: {}:{}'.format(ip, port))
    run(app=app, host=ip, port=port, debug=debug,
        reloader=True, server=GeventWebSocketServer) 
Example #13
Source File: webconsole_plugin.py    From rekall with GNU General Public License v2.0 4 votes vote down vote up
def _serve_wsgi(self):
        with self.worksheet_fd:
            app = manuskript_server.InitializeApp(
                plugins=self.PLUGINS,
                config=dict(
                    worksheet=self.worksheet_fd,
                ))

            # Use blueprint as an easy way to serve static files.
            bp = Blueprint('rekall-webconsole', __name__,
                           static_url_path="/rekall-webconsole",
                           static_folder=STATIC_PATH)

            @bp.after_request
            def add_header(response):  # pylint: disable=unused-variable
                response.headers['Cache-Control'] = 'no-cache, no-store'
                return response

            app.register_blueprint(bp)

            # Use blueprint as an easy way to serve static files.
            bp = Blueprint('worksheet', __name__,
                           static_url_path="/worksheet",
                           static_folder=self.worksheet_path)

            @bp.after_request
            def add_header_2(response):  # pylint: disable=unused-variable
                response.headers['Cache-Control'] = 'no-cache, no-store'
                return response

            app.register_blueprint(bp)

            server = pywsgi.WSGIServer(
                (self.host, self.port), app,
                environ={'wsgi.multithread': True},
                handler_class=WebSocketHandler)

            t = threading.Thread(target=self.server_post_activate_callback,
                                 args=(server,))
            t.start()

            server.serve_forever()