当前位置: 首页>>代码示例>>Python>>正文


Python socketio.Server方法代码示例

本文整理汇总了Python中socketio.Server方法的典型用法代码示例。如果您正苦于以下问题:Python socketio.Server方法的具体用法?Python socketio.Server怎么用?Python socketio.Server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socketio的用法示例。


在下文中一共展示了socketio.Server方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import socketio [as 别名]
# 或者: from socketio import Server [as 别名]
def __init__(self, m2m_app, port=None, listen_on="0.0.0.0", *args, **kw):
        super(FlaskRunner, self).__init__(m2m_app=m2m_app, port=port,
                                          listen_on=listen_on, *args, **kw)

        @self.flask_app.route("/")
        def home():
            return redirect(url_for('static', filename='index.html'))

        self.sio_app = SioServer(async_mode='gevent')

        @self.sio_app.on('connect')
        def connect(sid, environ):
            self.logger.debug('client connected: %s' % sid) 
开发者ID:OpenMTC,项目名称:OpenMTC,代码行数:15,代码来源:__init__.py

示例2: __init__

# 需要导入模块: import socketio [as 别名]
# 或者: from socketio import Server [as 别名]
def __init__(self, *arguments, runtime_overrides: List[Tuple[str, str, Any]] = None, skip_http_serve=False):
        self.msgs_lock = Lock()
        self.sio = socketio.Server(cors_allowed_origins="*", async_mode="threading")
        self.next_id_for_object = defaultdict(int)
        self.ui_objects: Dict[Union[rs.Spike, rs.Activation], Union[UISpikeModel, UIActivationModel]] = dict()
        self.sio.on("connect", self._authorize_client)
        self.session_client: Optional[SessionClient] = None
        self.config_parsed = Event()
        self.new_connection: Callable = lambda: None

        super().__init__(*arguments, runtime_overrides=runtime_overrides)
        if not skip_http_serve:
            Thread(target=self.ui_serve_events_async).start() 
开发者ID:Roboy,项目名称:ravestate,代码行数:15,代码来源:ui_context.py

示例3: start

# 需要导入模块: import socketio [as 别名]
# 或者: from socketio import Server [as 别名]
def start(self):
        self.sio = socketio.Server()
        self.sio.register_namespace(self)
        self.app = socketio.Middleware(self.sio, Flask(__name__))
        eventlet.wsgi.server(eventlet.listen(('', 4567)), self.app) 
开发者ID:thomasantony,项目名称:sdc-live-trainer,代码行数:7,代码来源:server.py

示例4: background_thread

# 需要导入模块: import socketio [as 别名]
# 或者: from socketio import Server [as 别名]
def background_thread():
    """Example of how to send server generated events to clients."""
    count = 0
    while True:
        sio.sleep(10)
        count += 1
        sio.emit('my_response', {'data': 'Server generated event'}) 
开发者ID:miguelgrinberg,项目名称:python-socketio,代码行数:9,代码来源:app.py

示例5: background_thread

# 需要导入模块: import socketio [as 别名]
# 或者: from socketio import Server [as 别名]
def background_thread():
    """Example of how to send server generated events to clients."""
    count = 0
    while True:
        sio.sleep(10)
        count += 1
        sio.emit('my_response', {'data': 'Server generated event'},
                 namespace='/test') 
开发者ID:miguelgrinberg,项目名称:python-socketio,代码行数:10,代码来源:views.py

示例6: run

# 需要导入模块: import socketio [as 别名]
# 或者: from socketio import Server [as 别名]
def run(browser=True):
    port = 5000
    if len(sys.argv) > 1:
        port = int(sys.argv[1])

    app = Flask(__name__, static_folder=static_path)
    app.register_blueprint(Index().register())

    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")

    console = StreamHandler()
    console.setLevel(logging.DEBUG)
    console.setFormatter(formatter)
    logger.addHandler(console)

    if not app.debug:
        file = TimedRotatingFileHandler(data_path + "/error.log", when="w0", backupCount=14)
        file.setLevel(logging.ERROR)
        file.setFormatter(formatter)
        logger.addHandler(file)

    try:
        config = Config()
        secret_key = config.read("secret_key")
        if not secret_key:
            secret_key = "".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(16))
            config.write("secret_key", secret_key)
        app.secret_key = secret_key

        Storage().init()

        sockets = socketio.Server()
        app.wsgi_app = socketio.Middleware(sockets, app.wsgi_app)
        sockets.register_namespace(Backend())

        def open_in_browser():
            logging.info("Application is starting...")

            url = "http://127.0.0.1:%s" % port
            while not url_ok(url):
                sleep(0.5)

            logging.info("Application is available at " + url)

            if not app.debug and browser:
                webbrowser.open(url)

        Thread(target=open_in_browser, daemon=True).start()

        app.run(host="0.0.0.0", port=port, threaded=True, use_reloader=False)

    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        logging.exception(sys.exc_info()[0]) 
开发者ID:kolinger,项目名称:rd-usb,代码行数:59,代码来源:web.py


注:本文中的socketio.Server方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。