本文整理汇总了Python中socketio.server.SocketIOServer.serve_forever方法的典型用法代码示例。如果您正苦于以下问题:Python SocketIOServer.serve_forever方法的具体用法?Python SocketIOServer.serve_forever怎么用?Python SocketIOServer.serve_forever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socketio.server.SocketIOServer
的用法示例。
在下文中一共展示了SocketIOServer.serve_forever方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: socketio_server
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def socketio_server():
#server = SocketIOServer(('0.0.0.0', 0), SocketApp(), policy_server=False)
server = SocketIOServer(('0.0.0.0', 38477), SocketApp(), policy_server=False)
server.start()
port = server.socket.getsockname()[1]
print 'http://localhost:'+str(port)+'/'
server.serve_forever()
示例2: cli_server_socketio
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def cli_server_socketio(
managed,
listen=None,
application=None,
port=None,
**kwargs
):
try:
from socketio.server import SocketIOServer
except ImportError:
print(
'import of socketio.server failed, bailing',
file=sys.stderr,
)
sys.exit(1)
if not managed and application is None:
# inspect the caller
outer_frame = inspect.getouterframes(inspect.currentframe())[2][0]
app = outer_frame.f_globals['application']
else:
app = application
# Managed (i.e. invoked by 'rain serve') invocations doesn't have the
# ``listen`` parameter passed in, but have ``port`` set.
# Just make up one listening on localhost.
if managed and listen is None:
listen = ('0.0.0.0', port, )
server = SocketIOServer(listen, app, **kwargs)
server.serve_forever()
示例3: run_dev_server
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def run_dev_server():
global server
app.debug = True
port = 5000
dapp = DebuggedApplicationFix(app, evalex = True)
server = SocketIOServer(('' if len(sys.argv) == 1 else sys.argv[1], port), dapp, resource="socket.io")
server.serve_forever()
示例4: socketio_server
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def socketio_server():
server = SocketIOServer(
('0.0.0.0', port),
SocketApp(),
policy_server=False)
server.start()
server.serve_forever()
示例5: start_server
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def start_server(self, addrport="", *args, **options):
if not addrport:
self.addr = '127.0.0.1'
self.port = DEFAULT_PORT
else:
m = match(naiveip_re, addrport)
if m is None:
raise CommandError('"%s" is not a valid port number '
'or address:port pair.' % addrport)
self.addr, _, _, _, self.port = m.groups()
# Make the port available here for the path:
# socketio_tags.socketio ->
# socketio_scripts.html ->
# io.Socket JS constructor
# allowing the port to be set as the client-side default there.
environ["DJANGO_SOCKETIO_PORT"] = str(self.port)
bind = (self.addr, int(self.port))
print
print "SocketIOServer running on http://%s:%s" % bind
print
handler = self.get_handler(*args, **options)
server = SocketIOServer(bind, handler, resource="zircon",
policy_server=True)
server.serve_forever()
示例6: handle
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def handle(self, addrport="", *args, **options):
if not addrport:
self.addr = ''
self.port = DEFAULT_PORT
else:
m = match(naiveip_re, addrport)
if m is None:
raise CommandError('"%s" is not a valid port number '
'or address:port pair.' % addrport)
self.addr, _, _, _, self.port = m.groups()
# Make the port available here for the path:
# socketio_tags.socketio ->
# socketio_scripts.html ->
# io.Socket JS constructor
# allowing the port to be set as the client-side default there.
environ["DJANGO_SOCKETIO_PORT"] = str(self.port)
start_new_thread(reload_watcher, ())
try:
bind = (self.addr, int(self.port))
print
print "SocketIOServer running on %s:%s" % bind
print
handler = self.get_handler(*args, **options)
server = SocketIOServer(bind, handler, resource="socket.io", policy_server=True)
server.serve_forever()
except KeyboardInterrupt:
if RELOAD:
server.stop()
print "Reloading..."
restart_with_reloader()
else:
raise
示例7: run_gevent_server
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def run_gevent_server(self):
server = SocketIOServer(
(self.host, self.port),
self.app, namespace='socket.io',
policy_server=False)
log.info('Web server running on %s:%s', self.host, self.port)
server.serve_forever()
示例8: handle
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def handle(self, addrport="", *args, **options):
if not addrport:
self.addr = ""
self.port = DEFAULT_PORT
else:
m = match(naiveip_re, addrport)
if m is None:
raise CommandError('"%s" is not a valid port number ' "or address:port pair." % addrport)
self.addr, _, _, _, self.port = m.groups()
environ["DJANGO_SOCKETIO_PORT"] = str(self.port)
if options.get("use_reloader"):
start_new_thread(reload_watcher, ())
try:
bind = (self.addr, int(self.port))
print "SocketIOServer running on %s:%s\n\n" % bind
handler = self.get_handler(*args, **options)
server = SocketIOServer(bind, handler, resource="socket.io", policy_server=True)
server.serve_forever()
except KeyboardInterrupt:
for key, sock in six.iteritems(server.sockets):
sock.kill(detach=True)
server.stop()
if RELOAD:
print "Reloading...\n\n"
restart_with_reloader()
示例9: run
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def run(addrport, opts):
if not addrport:
addr = ''
port = settings.SIO_PORT
else:
m = match(naiveip_re, addrport)
if m is None:
raise Exception('"%s" is not a valid port number '
'or address:port pair.' % addrport)
addr, _, _, _, port = m.groups()
# Make the port available here for the path:
# socketio_tags.socketio ->
# socketio_scripts.html ->
# io.Socket JS constructor
# allowing the port to be set as the client-side default there.
os.environ["DJANGO_SOCKETIO_PORT"] = str(port)
django.setup()
try:
bind = (addr, int(port))
print
print "SocketIOServer running on %s:%s" % bind
print
#inject this setting - needed to initialize zmq in 'green' mode
settings._wrapped.USE_GEVENT=True
handler = get_handler(static=opts.use_static_handler)
server = SocketIOServer(bind, handler, resource="socket.io", policy_server=True)
server.serve_forever()
except KeyboardInterrupt:
pass
示例10: spawn_server
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def spawn_server(func, port):
print "Serving port", port, func.__name__
server = SocketIOServer(("localhost", port), func,
spawn=greenlet_pool,
cors="http://localhost:3000",
policy_server=False)
server.serve_forever()
示例11: main
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def main(self, host, port):
got_request_exception.connect(exception_printer)
self.stdout.write('Serving at {host}:{port}\n'.format(host = host, port = port))
application = WSGIHandler()
server = SocketIOServer((host, port), application, namespace = 'socket.io', policy_server = False)
server.serve_forever()
示例12: start_server
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def start_server(host_address):
try:
server = SocketIOServer(host_address, app, resource='socket.io')
server.serve_forever()
except:
# assume for now server is already running
pass
示例13: run_server
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def run_server():
#app.run('0.0.0.0', 8080, debug=True)
global app
print 'Starting SocketIO Server with Gevent Mode ...'
app = SharedDataMiddleware(app, {})
http_server = SocketIOServer(('', 80), app, namespace="socket.io", policy_server=False)
http_server.serve_forever()
示例14: foo
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def foo():
server = SocketIOServer(
(host, port),
app,
namespace="socket.io",
policy_server=False
)
server.serve_forever()
示例15: main
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import serve_forever [as 别名]
def main():
parser = argparse.ArgumentParser(description='Marteau Server')
parser.add_argument('config', help='Config file', nargs='?')
parser.add_argument('--version', action='store_true',
default=False,
help='Displays Marteau version and exits.')
parser.add_argument('--log-level', dest='loglevel', default='info',
choices=LOG_LEVELS.keys() + [key.upper() for key in
LOG_LEVELS.keys()],
help="log level")
parser.add_argument('--log-output', dest='logoutput', default='-',
help="log output")
parser.add_argument('--host', help='Host', default='0.0.0.0')
parser.add_argument('--port', help='Port', type=int, default=8080)
args = parser.parse_args()
if args.version:
print(__version__)
sys.exit(0)
if args.config is None:
parser.print_usage()
sys.exit(0)
# configure the logger
configure_logger(logger, args.loglevel, args.logoutput)
# loading the config file
config = Config(args.config)
# loading the app & the queue
global_config = {}
if config.has_section('marteau'):
settings = config.get_map('marteau')
else:
settings = {}
# check is redis is running
if not redis_available():
raise IOError('Marteau needs Redis to run.')
# loading the fixtures plugins
for fixture in settings.get('fixtures', []):
import_string(fixture)
logger.info('Loaded plugins: %s' % ', '.join(get_fixtures()))
app = webapp(global_config, **settings)
try:
httpd = SocketIOServer((args.host, args.port), app,
resource="socket.io", policy_server=False)
logger.info('Hammer ready, at http://%s:%s. Where are the nails ?' %
(args.host, args.port))
httpd.serve_forever()
except KeyboardInterrupt:
sys.exit(0)
finally:
logger.info('Bye!')