本文整理汇总了Python中ws4py.server.cherrypyserver.WebSocketPlugin.manager方法的典型用法代码示例。如果您正苦于以下问题:Python WebSocketPlugin.manager方法的具体用法?Python WebSocketPlugin.manager怎么用?Python WebSocketPlugin.manager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ws4py.server.cherrypyserver.WebSocketPlugin
的用法示例。
在下文中一共展示了WebSocketPlugin.manager方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_cherrypy_debug_server
# 需要导入模块: from ws4py.server.cherrypyserver import WebSocketPlugin [as 别名]
# 或者: from ws4py.server.cherrypyserver.WebSocketPlugin import manager [as 别名]
def start_cherrypy_debug_server(htdocs_path,
http_host, http_port,
mpd_host, mpd_port=6600, mpd_password=None):
# set cherrypy configuration.
cherrypy.config.update({'server.socket_port': http_port})
cherrypy.config.update({'server.socket_host': http_host})
if (not os.path.isdir(htdocs_path)):
print("=" * 80 + """
The ympd htdocs dir is not available: perhaps the git submodule is missing?
""" + "=" * 80)
sys.exit(1)
# Add the websocket requirements.
a = WebSocketPlugin(cherrypy.engine)
a.manager = WebSocketManager()
a.subscribe()
cherrypy.tools.websocket = WebSocketTool()
web_root = Root()
# get a function to instantiate the websocket with the correct settings.
ympd_websocket = ympdWebSocket_wrap(mpd_host, mpd_port, mpd_password)
# Run a no-websocket alternative at http://hostname:port/nows/
nowebsocket = ympdNoWebSocket_wrap(mpd_host, mpd_port, mpd_password)
web_root.nows = nowebsocket(htdocs_path)
# this implementation uses POST requests communicate.
# Takes a little bit longer for the UI to update, but it should get through
# firewalls and proxies where the websocket cannot.
cherrypy.quickstart(web_root, '/', config={
'/ws': {'tools.websocket.on': True,
'tools.websocket.handler_cls': ympd_websocket},
'/': {'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(htdocs_path),
"tools.staticdir.index": "index.html"},
}
)
示例2: _configure_server
# 需要导入模块: from ws4py.server.cherrypyserver import WebSocketPlugin [as 别名]
# 或者: from ws4py.server.cherrypyserver.WebSocketPlugin import manager [as 别名]
def _configure_server(restarting=False):
global websocket_plugin
# Configure server error log
cherrypy.config.update({'log.error_file': 'cherrypy.error.log'})
# Configure server url
cherrypy.config.update({'server.socket_host': s2n(autosubliminal.WEBSERVERIP),
'server.socket_port': int(autosubliminal.WEBSERVERPORT)
})
# Disable engine plugins (no need for autoreload plugin)
cherrypy.config.update({'engine.autoreload.on': False})
# Read and store cherrypy server version (if not set, it returns CherryPy/Unknown because it's not installed)
server_header = 'CherryPy/%s' % get_library_version('cherrypy')
cherrypy.config.update({'response.headers.server': server_header})
# Configure authentication in if a username and password is set by the user
if autosubliminal.USERNAME and autosubliminal.PASSWORD:
users = {s2n(autosubliminal.USERNAME): s2n(autosubliminal.PASSWORD)}
cherrypy.config.update({'tools.auth_digest.on': True,
'tools.auth_digest.realm': 'Auto-Subliminal website',
'tools.auth_digest.get_ha1': auth_digest.get_ha1_dict_plain(users),
'tools.auth_digest.key': 'yek.tsegid_htua.lanimilbuS-otuA' # Can be any random string
})
# Configure our custom json_out_handler (Uncomment if it should be used for any @cherrypy.tools.json_out())
# cherrypy.config.update({'tools.json_out.handler': json_out_handler})
if not restarting:
# Enable websocket plugin
websocket_plugin = WebSocketPlugin(cherrypy.engine)
websocket_plugin.subscribe()
cherrypy.tools.websocket = WebSocketTool()
else:
# When restarting we need to create a new websocket manager thread (you cannot start the same thread twice!)
websocket_plugin.manager = WebSocketManager()
# When restarting we need to clear the httpserver to force the creation of a new one (needed for ip/port change)
cherrypy.server.httpserver = None
示例3: print
# 需要导入模块: from ws4py.server.cherrypyserver import WebSocketPlugin [as 别名]
# 或者: from ws4py.server.cherrypyserver.WebSocketPlugin import manager [as 别名]
formatter = logging.Formatter('%(name)s - %(asctime)s - %(levelname)s'
' - %(message)s')
ch.setFormatter(formatter)
interface_logger.addHandler(ch)
# create the preset folder if it does not exist:
preset_dir = os.path.abspath(args.presetdir)
if (not os.path.isdir(preset_dir)):
print("Preset folder {} did not exist, creating.".format(preset_dir))
os.makedirs(preset_dir)
# Add the websocket requirements.
cherrypy.tools.websocket = WebSocketTool()
a = WebSocketPlugin(cherrypy.engine)
a.manager = WebSocketManager()
a.subscribe()
stack_interface = interface.StackInterface()
stack_interface.daemon = True
stack_interface.start()
server_tree = FocusStackRoot(stack_interface, preset_dir=preset_dir)
# create a broadcast function which relays messages received over the
# serial port to the websockets via the websocketmanager.
def broadcaster():
m = stack_interface.get_message()
if m:
payload = dict(m)
payload["msg_type"] = message.msg_type_name[payload["msg_type"]]
msg = ["serial", payload]