本文整理汇总了Python中socketio.server.SocketIOServer类的典型用法代码示例。如果您正苦于以下问题:Python SocketIOServer类的具体用法?Python SocketIOServer怎么用?Python SocketIOServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SocketIOServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
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()
示例2: start_server
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()
示例3: run_gevent_server
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()
示例4: spawn_server
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()
示例5: run
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
示例6: main
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()
示例7: run_dev_server
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()
示例8: start_server
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
示例9: socketio_server
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()
示例10: cli_server_socketio
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()
示例11: socketio_server
def socketio_server():
server = SocketIOServer(
('0.0.0.0', port),
SocketApp(),
policy_server=False)
server.start()
server.serve_forever()
示例12: handle
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
示例13: run_server
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
def foo():
server = SocketIOServer(
(host, port),
app,
namespace="socket.io",
policy_server=False
)
server.serve_forever()
示例15: main
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!')