本文整理汇总了Python中socketio.server.SocketIOServer.stop方法的典型用法代码示例。如果您正苦于以下问题:Python SocketIOServer.stop方法的具体用法?Python SocketIOServer.stop怎么用?Python SocketIOServer.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socketio.server.SocketIOServer
的用法示例。
在下文中一共展示了SocketIOServer.stop方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import stop [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()
示例2: handle
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import stop [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
示例3: handle
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import stop [as 别名]
def handle(self, addrport='', *args, **options):
"""
Parses all arguments and starts the server. Will reload on
SIGINT unless the --noreload flag is passed.
"""
if options.get('enable_coverage'):
print "Enabling coverage for socketio server."
coverage_omit = ['*/management/*',
'*/migrations/*']
cov = coverage.coverage(source=['deckr'],
omit=coverage_omit,
data_suffix=True)
cov.start()
if not addrport:
self.addr = ''
self.port = DEFAULT_PORT
else:
address_match = match(naiveip_re, addrport)
if address_match is None:
raise CommandError('"%s" is not a valid port number '
'or address:port pair.' % addrport)
self.addr, _, _, _, self.port = address_match.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 = get_handler(**options)
server = SocketIOServer(
bind, handler, resource='socket.io', policy_server=True)
server.serve_forever()
except KeyboardInterrupt:
server.stop()
if options.get('enable_coverage'):
cov.stop()
cov.save()
if RELOAD:
print 'Reloading...\n\n'
restart_with_reloader()
示例4: go
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import stop [as 别名]
def go():
# must import namespace class here after os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from namespaces import SimplePushNS, RootNamespace
# Dummy request object to maintain state between Namespace initialization.
# just for ChatNamespace share data
request = {'self_reported': False, 'pid': PID, 'ip': IP}
# here can assign several namespaces pair by key:value
application = NSWSGIHandler({'': RootNamespace, '/simplepush': SimplePushNS}, request)
sio = SocketIOServer(('0.0.0.0', PORT), application, resource="socket.io", log=None)
# log_file="request.log", handler_class=LogSocketIOHandler,) # JUST WRITE ACCESS LOG TO FILE
print 'SocketIOServer Listening on http://0.0.0.0:%s and on port 10843 (flash policy server)' % PORT
print 'PID is: %s' % PID
try:
sio.serve_forever()
except KeyboardInterrupt:
sio.stop()
print ' >>> SocketIO Server Stopped!'
示例5: handle
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import stop [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_psyco'):
try:
from psycogreen.gevent import patch_psycopg
except ImportError:
raise CommandError(
'Could not patch psycopg. '
'Is psycogreen installed?')
patch_psycopg()
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:
socks = []
for key, sock in six.iteritems(server.sockets):
socks.append(sock)
for sock in socks:
sock.kill(detach=True)
server.stop()
if RELOAD:
print 'Reloading...\n\n'
restart_with_reloader()
示例6: main
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import stop [as 别名]
def main():
try:
# init
# lModel = RangeManager(int(sys.argv[1]), int(sys.argv[2]))
monkey.patch_all()
lApp = Flask(__name__)
lApp.debug = True
lApi = Api(lApp)
# FetchRange.sModel = lModel
# Report.sModel = lModel
# Progress.sModel = lModel
# Reset.sModel = lModel
# PushNamespace.sModel = lModel
# routes
lApp.add_url_rule('/', 'start', start)
# lApp.add_url_rule('/socket.io/<path:path>', 'socket.io', run_socketio)
lApi.add_resource(Busses, '/busses')
lApi.add_resource(IOConfig, '/ioconfig')
lApi.add_resource(Set, '/set')
lApi.add_resource(Get, '/get')
lApi.add_resource(Dump, '/dump')
lApi.add_resource(Detect, '/detect')
# go
# lApp = SharedDataMiddleware(lApp, {})
lServer = SocketIOServer(
('0.0.0.0', 5000),
lApp,
resource="socket.io",
policy_server=False)
lServer.serve_forever()
except IndexError:
print "Usage: " + sys.argv[0] + \
" <number of ranges> <timeout per range>"
except KeyboardInterrupt:
lServer.stop()
示例7: handle
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import stop [as 别名]
def handle(self, addrport="", *args, **options):
if not addrport:
self.addr = "127.0.0.1"
self.port = DEFAULT_PORT
else:
m = re.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()
if self.addr is None:
self.addr = "0.0.0.0"
# 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(self.port)
start_new_thread(reload_watcher, ())
try:
bind = (self.addr, int(self.port))
self.stdout.write("Starting development SocketIO server at %s:%s\n" % bind)
handler = self.get_handler(*args, **options)
server = SocketIOServer(bind, handler, resource="socket.io", policy_server=True, policy_listener=None)
server.serve_forever()
except KeyboardInterrupt:
if RELOAD:
server.stop()
self.stdout.write("Reloading...")
restart_with_reloader()
else:
raise
except Exception as e:
raise
示例8: main
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import stop [as 别名]
def main():
try:
# init
lModel = RangeManager(int(sys.argv[1]), int(sys.argv[2]))
monkey.patch_all()
lApp = Flask(__name__)
lApp.debug = True
lApi = Api(lApp)
FetchRange.sModel = lModel
Report.sModel = lModel
Progress.sModel = lModel
Reset.sModel = lModel
PushNamespace.sModel = lModel
# routes
lApp.add_url_rule('/', 'poll', poll)
lApp.add_url_rule('/socket.io/<path:path>', 'socket.io', run_socketio)
lApi.add_resource(FetchRange, '/fetch')
lApi.add_resource(Report, '/report')
lApi.add_resource(Progress, '/progress')
lApi.add_resource(Reset, '/reset')
# go
lApp = SharedDataMiddleware(lApp, {})
lServer = SocketIOServer(
('0.0.0.0', 5000),
lApp,
resource="socket.io",
policy_server=False)
lServer.serve_forever()
except IndexError:
print "Usage: " + sys.argv[0] + \
" <number of ranges> <timeout per range>"
except KeyboardInterrupt:
lServer.stop()
示例9: start_response
# 需要导入模块: from socketio.server import SocketIOServer [as 别名]
# 或者: from socketio.server.SocketIOServer import stop [as 别名]
content_type = "text/css"
elif path.endswith(".png"):
content_type = "image/png"
elif path.endswith(".swf"):
content_type = "application/x-shockwave-flash"
else:
content_type = "text/html"
start_response('200 OK', [('Content-Type', content_type)])
return [data]
# socketIO request
if path.startswith('socket.io/'):
socketio_manage(env, {'': LogStreamNS})
else:
return http404(start_response)
if __name__ == '__main__':
""" Main command line run """
try:
server = SocketIOServer(
('0.0.0.0', 8000), application, resource='socket.io', policy_server=True, policy_listener=('0.0.0.0', 10843)
)
sub = gevent.spawn(SubLogger)
sub.link(server.stop)
server.serve_forever()
except KeyboardInterrupt:
server.stop()