def __init__(self, *args, **kwargs): """ This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param resource: The URL which has to be identified as a socket.io request. Defaults to the /socket.io/ URL. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. :param policy_listener : A tuple containing (host, port) for the policy server. This is optional and used only if policy server is set to true. The default value is 0.0.0.0:843 """ self.sockets = {} if 'namespace' in kwargs: print("DEPRECATION WARNING: use resource instead of namespace") self.resource = kwargs.pop('namespace', 'socket.io') else: self.resource = kwargs.pop('resource', 'socket.io') self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): policylistener = kwargs.pop('policy_listener', (args[0][0], 10843)) self.policy_server = FlashPolicyServer(policylistener) else: self.policy_server = None kwargs['handler_class'] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs)
class SocketIOServer(WSGIServer): """A WSGI Server with a resource that acts like an SocketIO.""" def __init__(self, *args, **kwargs): self.sockets = {} if "resource" in kwargs: print "DEPRECATION WARNING: use `namespace` instead of `resource`" self.namespace = kwargs.pop("resource", kwargs.pop("namespace", "socket.io")) self.transports = kwargs.pop("transports", None) if kwargs.pop("policy_server", True): self.policy_server = FlashPolicyServer() else: self.policy_server = None kwargs["handler_class"] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs) def start_accepting(self): if self.policy_server is not None: try: self.policy_server.start() except error, ex: sys.stderr.write("FAILED to start flash policy server: %s\n" % (ex,)) except Exception: traceback.print_exc() sys.stderr.write("FAILED to start flash policy server.\n\n")
def __init__(self, *args, **kwargs): """ This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param namespace: The namespace to use. Defaults to the global namespace. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. """ self.sockets = {} if 'resource' in kwargs: print "DEPRECATION WARNING: use `namespace` instead of `resource`" self.namespace = kwargs.pop('resource', kwargs.pop('namespace', 'socket.io')) self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): self.policy_server = FlashPolicyServer() else: self.policy_server = None kwargs['handler_class'] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.sessions = {} self.resource = kwargs.pop('resource') if kwargs.pop('policy_server', True): self.policy_server = FlashPolicyServer() else: self.policy_server = None kwargs['handler_class'] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs)
class SocketIOServer(WSGIServer): """A WSGI Server with a resource that acts like an SocketIO.""" def __init__(self, *args, **kwargs): """ This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param resource: The URL which has to be identified as a socket.io request. Defaults to the /socket.io/ URL. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. :param policy_listener : A tuple containing (host, port) for the policy server. This is optional and used only if policy server is set to true. The default value is 0.0.0.0:843 """ self.sockets = {} if 'namespace' in kwargs: print("DEPRECATION WARNING: use resource instead of namespace") self.resource = kwargs.pop('namespace', 'socket.io') else: self.resource = kwargs.pop('resource', 'socket.io') self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): try: address = args[0][0] except TypeError: address = args[0].address[0] policylistener = kwargs.pop('policy_listener', (address, 10843)) self.policy_server = FlashPolicyServer(policylistener) else: self.policy_server = None kwargs['handler_class'] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs) def start_accepting(self): if self.policy_server is not None: try: if not self.policy_server.started: self.policy_server.start() except error, ex: sys.stderr.write( 'FAILED to start flash policy server: %s\n' % (ex, )) except Exception: traceback.print_exc() sys.stderr.write('FAILED to start flash policy server.\n\n')
def __init__(self, *args, **kwargs): address_family = kwargs.pop('address_family', socket.AF_INET) socket_type = kwargs.pop('socket_type', socket.SOCK_STREAM) backlog = kwargs.pop('backlog', 2048) listener = args[0] if isinstance(listener, tuple): host, port = listener _socket = create_socket(host, port, address_family, socket_type, backlog=backlog) _socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) args = [_socket] + list(args[1:]) else: # it's already a socket.. host, port = listener.getsockname() # socketio makes the assumption that listener is a host/port # tuple, which is a false assumption, it can be a socket. # it uses listener in its constructor to set the policy server # # Let's set it ourselves here afterwards. old_policy_server = kwargs.pop('policy_server', True) kwargs['policy_server'] = False super(Server, self).__init__(*args, **kwargs) if old_policy_server: policylistener = kwargs.pop('policy_listener', (host, 10843)) self.policy_server = FlashPolicyServer(policylistener)
def __init__(self, *args, **kwargs): """This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param resource: The URL which has to be identified as a socket.io request. Defaults to the /socket.io/ URL. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. :param policy_listener : A tuple containing (host, port) for the policy server. This is optional and used only if policy server is set to true. The default value is 0.0.0.0:843 :param heartbeat_interval: int The timeout for the server, we should receive a heartbeat from the client within this interval. This should be less than the ``heartbeat_timeout``. :param heartbeat_timeout: int The timeout for the client when it should send a new heartbeat to the server. This value is sent to the client after a successful handshake. :param close_timeout: int The timeout for the client, when it closes the connection it still X amounts of seconds to do re open of the connection. This value is sent to the client after a successful handshake. """ self.sockets = {} if "namespace" in kwargs: print("DEPRECATION WARNING: use resource instead of namespace") self.resource = kwargs.pop("namespace", "socket.io") else: self.resource = kwargs.pop("resource", "socket.io") self.transports = kwargs.pop("transports", None) if kwargs.pop("policy_server", True): try: address = args[0][0] except TypeError: address = args[0].address[0] policylistener = kwargs.pop("policy_listener", (address, 10843)) self.policy_server = FlashPolicyServer(policylistener) else: self.policy_server = None # Extract other config options self.config = {"heartbeat_timeout": 60, "close_timeout": 60, "heartbeat_interval": 25} for f in ("heartbeat_timeout", "heartbeat_interval", "close_timeout"): if f in kwargs: self.config[f] = int(kwargs.pop(f)) kwargs["handler_class"] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs)
class SocketIOServer(WSGIServer): """A WSGI Server with a resource that acts like an SocketIO.""" def __init__(self, *args, **kwargs): """ This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param namespace: The namespace to use. Defaults to the global namespace. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. """ self.sockets = {} if 'resource' in kwargs: print "DEPRECATION WARNING: use `namespace` instead of `resource`" self.namespace = kwargs.pop('resource', kwargs.pop('namespace', 'socket.io')) self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): policylistener = kwargs.pop('policy_listener', (args[0][0], 843)) self.policy_server = FlashPolicyServer(policylistener) else: self.policy_server = None kwargs['handler_class'] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs) def start_accepting(self): if self.policy_server is not None: try: self.policy_server.start() except error, ex: sys.stderr.write( 'FAILED to start flash policy server: %s\n' % (ex, )) except Exception: traceback.print_exc() sys.stderr.write('FAILED to start flash policy server.\n\n')
class SocketIOServer(WSGIServer): """A WSGI Server with a resource that acts like an SocketIO.""" def __init__(self, *args, **kwargs): """ This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param namespace: The namespace to use. Defaults to the global namespace. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. """ self.sockets = {} if 'resource' in kwargs: print "DEPRECATION WARNING: use `namespace` instead of `resource`" self.namespace = kwargs.pop('resource', kwargs.pop('namespace', 'socket.io')) self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): self.policy_server = FlashPolicyServer() else: self.policy_server = None kwargs['handler_class'] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs) def start_accepting(self): if self.policy_server is not None: try: self.policy_server.start() except error, ex: sys.stderr.write('FAILED to start flash policy server: %s\n' % (ex, )) except Exception: traceback.print_exc() sys.stderr.write('FAILED to start flash policy server.\n\n')
class SocketIOServer(WSGIServer): """A WSGI Server with a resource that acts like an SocketIO.""" def __init__(self, *args, **kwargs): self.sessions = {} self.resource = kwargs.pop('resource') if kwargs.pop('policy_server', True): self.policy_server = FlashPolicyServer() else: self.policy_server = None kwargs['handler_class'] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs) def start_accepting(self): if self.policy_server is not None: try: self.policy_server.start() except error, ex: sys.stderr.write('FAILED to start flash policy server: %s\n' % (ex, )) except Exception: traceback.print_exc() sys.stderr.write('FAILED to start flash policy server.\n\n')
def __init__(self, *args, **kwargs): self.resource = kwargs.pop('resource') if kwargs.pop('policy_server', False): self.policy_server = FlashPolicyServer() else: self.policy_server = None self.worker = kwargs.pop('worker', None) kwargs['handler_class'] = RedBarrelSocketIOHandler if kwargs.pop('memory', True): self.sessions = RedBarrelSessionManager(MEM) else: self.sessions = RedBarrelSessionManager(REDIS) super(SocketIOServer, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.sockets = {} if "resource" in kwargs: print "DEPRECATION WARNING: use `namespace` instead of `resource`" self.namespace = kwargs.pop("resource", kwargs.pop("namespace", "socket.io")) self.transports = kwargs.pop("transports", None) if kwargs.pop("policy_server", True): self.policy_server = FlashPolicyServer() else: self.policy_server = None kwargs["handler_class"] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.sockets = {} if 'resource' in kwargs: print "DEPRECATION WARNING: use `namespace` instead of `resource`" self.namespace = kwargs.pop('resource', kwargs.pop('namespace', 'socket.io')) self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): self.policy_server = FlashPolicyServer() else: self.policy_server = None kwargs['handler_class'] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): """This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param resource: The URL which has to be identified as a socket.io request. Defaults to the /socket.io/ URL. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. :param policy_listener: A tuple containing (host, port) for the policy server. This is optional and used only if policy server is set to true. The default value is 0.0.0.0:843 :param heartbeat_interval: int The timeout for the server, we should receive a heartbeat from the client within this interval. This should be less than the ``heartbeat_timeout``. :param heartbeat_timeout: int The timeout for the client when it should send a new heartbeat to the server. This value is sent to the client after a successful handshake. :param close_timeout: int The timeout for the client, when it closes the connection it still X amounts of seconds to do re open of the connection. This value is sent to the client after a successful handshake. :param log_file: str The file in which you want the PyWSGI server to write its access log. If not specified, it is sent to `stderr` (with gevent 0.13). """ self.sockets = {} if 'namespace' in kwargs: print("DEPRECATION WARNING: use resource instead of namespace") self.resource = kwargs.pop('namespace', 'socket.io') else: self.resource = kwargs.pop('resource', 'socket.io') self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): try: address = args[0][0] except TypeError: try: address = args[0].address[0] except AttributeError: address = args[0].cfg_addr[0] policylistener = kwargs.pop('policy_listener', (address, 10843)) self.policy_server = FlashPolicyServer(policylistener) else: self.policy_server = None # Extract other config options self.config = { 'heartbeat_timeout': 60, 'close_timeout': 60, 'heartbeat_interval': 25, } for f in ('heartbeat_timeout', 'heartbeat_interval', 'close_timeout'): if f in kwargs: self.config[f] = int(kwargs.pop(f)) if not 'handler_class' in kwargs: kwargs['handler_class'] = SocketIOHandler if not 'ws_handler_class' in kwargs: self.ws_handler_class = WebSocketHandler else: self.ws_handler_class = kwargs.pop('ws_handler_class') log_file = kwargs.pop('log_file', None) if log_file: kwargs['log'] = open(log_file, 'a') super(SocketIOServer, self).__init__(*args, **kwargs)
class SocketIOServer(WSGIServer): """A WSGI Server with a resource that acts like an SocketIO.""" def __init__(self, *args, **kwargs): """This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param resource: The URL which has to be identified as a socket.io request. Defaults to the /socket.io/ URL. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. :param policy_listener : A tuple containing (host, port) for the policy server. This is optional and used only if policy server is set to true. The default value is 0.0.0.0:843 :param heartbeat_interval: int The timeout for the server, we should receive a heartbeat from the client within this interval. This should be less than the ``heartbeat_timeout``. :param heartbeat_timeout: int The timeout for the client when it should send a new heartbeat to the server. This value is sent to the client after a successful handshake. :param close_timeout: int The timeout for the client, when it closes the connection it still X amounts of seconds to do re open of the connection. This value is sent to the client after a successful handshake. """ self.sockets = {} if 'namespace' in kwargs: print("DEPRECATION WARNING: use resource instead of namespace") self.resource = kwargs.pop('namespace', 'socket.io') else: self.resource = kwargs.pop('resource', 'socket.io') self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): try: address = args[0][0] except TypeError: address = args[0].address[0] policylistener = kwargs.pop('policy_listener', (address, 10843)) self.policy_server = FlashPolicyServer(policylistener) else: self.policy_server = None # Extract other config options self.config = { 'heartbeat_timeout': 60, 'close_timeout': 60, 'heartbeat_interval': 25, } for f in ('heartbeat_timeout', 'heartbeat_interval', 'close_timeout'): if f in kwargs: self.config[f] = int(kwargs.pop(f)) if not 'handler_class' in kwargs: kwargs['handler_class'] = SocketIOHandler if not 'ws_handler_class' in kwargs: self.ws_handler_class = WebSocketHandler else: self.ws_handler_class = kwargs.pop('ws_handler_class') super(SocketIOServer, self).__init__(*args, **kwargs) def start_accepting(self): if self.policy_server is not None: try: if not self.policy_server.started: self.policy_server.start() except error, ex: sys.stderr.write( 'FAILED to start flash policy server: %s\n' % (ex, )) except Exception: traceback.print_exc() sys.stderr.write('FAILED to start flash policy server.\n\n')
class SocketIOServer(WSGIServer): """A WSGI Server with a resource that acts like an SocketIO.""" def __init__(self, *args, **kwargs): """This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param resource: The URL which has to be identified as a socket.io request. Defaults to the /socket.io/ URL. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. :param policy_listener: A tuple containing (host, port) for the policy server. This is optional and used only if policy server is set to true. The default value is 0.0.0.0:843 :param heartbeat_interval: int The timeout for the server, we should receive a heartbeat from the client within this interval. This should be less than the ``heartbeat_timeout``. :param heartbeat_timeout: int The timeout for the client when it should send a new heartbeat to the server. This value is sent to the client after a successful handshake. :param close_timeout: int The timeout for the client, when it closes the connection it still X amounts of seconds to do re open of the connection. This value is sent to the client after a successful handshake. :param log_file: str The file in which you want the PyWSGI server to write its access log. If not specified, it is sent to `stderr` (with gevent 0.13). """ self.sockets = {} if 'namespace' in kwargs: print("DEPRECATION WARNING: use resource instead of namespace") self.resource = kwargs.pop('namespace', 'socket.io') else: self.resource = kwargs.pop('resource', 'socket.io') self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): try: address = args[0][0] except TypeError: try: address = args[0].address[0] except AttributeError: address = args[0].cfg_addr[0] policylistener = kwargs.pop('policy_listener', (address, 10843)) self.policy_server = FlashPolicyServer(policylistener) else: self.policy_server = None # Extract other config options self.config = { 'heartbeat_timeout': 60, 'close_timeout': 60, 'heartbeat_interval': 25, } for f in ('heartbeat_timeout', 'heartbeat_interval', 'close_timeout'): if f in kwargs: self.config[f] = int(kwargs.pop(f)) if not 'handler_class' in kwargs: kwargs['handler_class'] = SocketIOHandler if not 'ws_handler_class' in kwargs: self.ws_handler_class = WebSocketHandler else: self.ws_handler_class = kwargs.pop('ws_handler_class') log_file = kwargs.pop('log_file', None) if log_file: kwargs['log'] = open(log_file, 'a') super(SocketIOServer, self).__init__(*args, **kwargs) def start_accepting(self): if self.policy_server is not None: try: if not self.policy_server.started: self.policy_server.start() except error: sys.stderr.write('FAILED to start flash policy server: %s\n' % (ex, )) except Exception: traceback.print_exc() sys.stderr.write('FAILED to start flash policy server.\n\n') super(SocketIOServer, self).start_accepting() def stop(self, timeout=None): if self.policy_server is not None: self.policy_server.stop() super(SocketIOServer, self).stop(timeout=timeout) def handle(self, socket, address): # Pass in the config about timeouts, heartbeats, also... handler = self.handler_class(self.config, socket, address, self) handler.handle() def get_socket(self, sessid=''): """Return an existing or new client Socket.""" socket = self.sockets.get(sessid) if sessid and not socket: return None # you ask for a session that doesn't exist! if socket is None: socket = Socket(self, self.config) self.sockets[socket.sessid] = socket else: socket.incr_hits() return socket
class SocketIOServer(WSGIServer): """A WSGI Server with a resource that acts like an SocketIO.""" def __init__(self, *args, **kwargs): """This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param resource: The URL which has to be identified as a socket.io request. Defaults to the /socket.io/ URL. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. :param policy_listener : A tuple containing (host, port) for the policy server. This is optional and used only if policy server is set to true. The default value is 0.0.0.0:843 :param heartbeat_interval: int The timeout for the server, we should receive a heartbeat from the client within this interval. This should be less than the ``heartbeat_timeout``. :param heartbeat_timeout: int The timeout for the client when it should send a new heartbeat to the server. This value is sent to the client after a successful handshake. :param close_timeout: int The timeout for the client, when it closes the connection it still X amounts of seconds to do re open of the connection. This value is sent to the client after a successful handshake. """ self.sockets = {} if 'namespace' in kwargs: print("DEPRECATION WARNING: use resource instead of namespace") self.resource = kwargs.pop('namespace', 'socket.io') else: self.resource = kwargs.pop('resource', 'socket.io') self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): try: address = args[0][0] except TypeError: address = args[0].address[0] policylistener = kwargs.pop('policy_listener', (address, 10843)) self.policy_server = FlashPolicyServer(policylistener) else: self.policy_server = None # Extract other config options self.config = { 'heartbeat_timeout': 60, 'close_timeout': 60, 'heartbeat_interval': 25, } for f in ('heartbeat_timeout', 'heartbeat_interval', 'close_timeout'): if f in kwargs: self.config[f] = int(kwargs.pop(f)) kwargs['handler_class'] = SocketIOHandler super(SocketIOServer, self).__init__(*args, **kwargs) def start_accepting(self): if self.policy_server is not None: try: if not self.policy_server.started: self.policy_server.start() except error, ex: sys.stderr.write('FAILED to start flash policy server: %s\n' % (ex, )) except Exception: traceback.print_exc() sys.stderr.write('FAILED to start flash policy server.\n\n')
class SocketIOServer(WSGIServer): """A WSGI Server with a resource that acts like an SocketIO.""" def __init__(self, *args, **kwargs): """This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param resource: The URL which has to be identified as a socket.io request. Defaults to the /socket.io/ URL. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. :param policy_listener: A tuple containing (host, port) for the policy server. This is optional and used only if policy server is set to true. The default value is 0.0.0.0:843 :param heartbeat_interval: int The timeout for the server, we should receive a heartbeat from the client within this interval. This should be less than the ``heartbeat_timeout``. :param heartbeat_timeout: int The timeout for the client when it should send a new heartbeat to the server. This value is sent to the client after a successful handshake. :param close_timeout: int The timeout for the client, when it closes the connection it still X amounts of seconds to do re open of the connection. This value is sent to the client after a successful handshake. :param log_file: str The file in which you want the PyWSGI server to write its access log. If not specified, it is sent to `stderr` (with gevent 0.13). """ self.sockets = {} if 'namespace' in kwargs: print("DEPRECATION WARNING: use resource instead of namespace") self.resource = kwargs.pop('namespace', 'socket.io') else: self.resource = kwargs.pop('resource', 'socket.io') self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): try: address = args[0][0] except TypeError: try: address = args[0].address[0] except AttributeError: address = args[0].cfg_addr[0] policylistener = kwargs.pop('policy_listener', (address, 10843)) self.policy_server = FlashPolicyServer(policylistener) else: self.policy_server = None # Extract other config options self.config = { 'heartbeat_timeout': 60, 'close_timeout': 60, 'heartbeat_interval': 25, } for f in ('heartbeat_timeout', 'heartbeat_interval', 'close_timeout'): if f in kwargs: self.config[f] = int(kwargs.pop(f)) if not 'handler_class' in kwargs: kwargs['handler_class'] = SocketIOHandler if not 'ws_handler_class' in kwargs: self.ws_handler_class = WebSocketHandler else: self.ws_handler_class = kwargs.pop('ws_handler_class') log_file = kwargs.pop('log_file', None) if log_file: kwargs['log'] = open(log_file, 'a') super(SocketIOServer, self).__init__(*args, **kwargs) def start_accepting(self): if self.policy_server is not None: try: if not self.policy_server.started: self.policy_server.start() except error as ex: sys.stderr.write( 'FAILED to start flash policy server: %s\n' % (ex, )) except Exception: traceback.print_exc() sys.stderr.write('FAILED to start flash policy server.\n\n') super(SocketIOServer, self).start_accepting() def stop(self, timeout=None): if self.policy_server is not None: self.policy_server.stop() super(SocketIOServer, self).stop(timeout=timeout) def handle(self, socket, address): # Pass in the config about timeouts, heartbeats, also... handler = self.handler_class(self.config, socket, address, self) handler.handle() def get_socket(self, sessid=''): """Return an existing or new client Socket.""" socket = self.sockets.get(sessid) if sessid and not socket: return None # you ask for a session that doesn't exist! if socket is None: socket = Socket(self, self.config) self.sockets[socket.sessid] = socket else: socket.incr_hits() return socket
def _get_server(self): return FlashPolicyServer()
class SocketIOServer(WSGIServer): """A WSGI Server with a resource that acts like an SocketIO.""" def __init__(self, *args, **kwargs): """This is just like the standard WSGIServer __init__, except with a few additional ``kwargs``: :param resource: The URL which has to be identified as a socket.io request. Defaults to the /socket.io/ URL. :param transports: Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types. :param policy_server: Boolean describing whether or not to use the Flash policy server. Default True. :param policy_listener: A tuple containing (host, port) for the policy server. This is optional and used only if policy server is set to true. The default value is 0.0.0.0:843 :param heartbeat_interval: int The timeout for the server, we should receive a heartbeat from the client within this interval. This should be less than the ``heartbeat_timeout``. :param heartbeat_timeout: int The timeout for the client when it should send a new heartbeat to the server. This value is sent to the client after a successful handshake. :param close_timeout: int The timeout for the client, when it closes the connection it still X amounts of seconds to do re open of the connection. This value is sent to the client after a successful handshake. :param log_file: str The file in which you want the PyWSGI server to write its access log. If not specified, it is sent to `stderr` (with gevent 0.13). """ if 'namespace' in kwargs: print("DEPRECATION WARNING: use resource instead of namespace") self.resource = kwargs.pop('namespace', 'socket.io') else: self.resource = kwargs.pop('resource', 'socket.io') self.transports = kwargs.pop('transports', None) if kwargs.pop('policy_server', True): try: address = args[0][0] except TypeError: try: address = args[0].address[0] except AttributeError: address = args[0].cfg_addr[0] policylistener = kwargs.pop('policy_listener', (address, 10843)) self.policy_server = FlashPolicyServer(policylistener) else: self.policy_server = None # Extract other config options self.config = { 'heartbeat_timeout': 60, 'close_timeout': 60, 'heartbeat_interval': 25, } for f in ('heartbeat_timeout', 'heartbeat_interval', 'close_timeout'): if f in kwargs: self.config[f] = int(kwargs.pop(f)) if not 'handler_class' in kwargs: kwargs['handler_class'] = SocketIOHandler if not 'ws_handler_class' in kwargs: self.ws_handler_class = WebSocketHandler else: self.ws_handler_class = kwargs.pop('ws_handler_class') log_file = kwargs.pop('log_file', None) if log_file: kwargs['log'] = open(log_file, 'a') if not 'socket_manager_config' in kwargs: socket_manager_config = {} else: socket_manager_config = kwargs.pop('socket_manager_config') self.config['socket_manager'] = socket_manager_config socket_manager_class = socket_manager_config.get("class", None) if not socket_manager_class: socket_manager_class = SocketManager else: #dynamically import the manager class (must be absolute class path!) module_name, class_name = socket_manager_class.rsplit('.', 1) mod = __import__(module_name, fromlist=[class_name]) socket_manager_class = getattr(mod, class_name) self.socket_manager = socket_manager_class(self.config) super(SocketIOServer, self).__init__(*args, **kwargs) def start(self): self.socket_manager.start() super(SocketIOServer, self).start() def start_accepting(self): if self.policy_server is not None: try: if not self.policy_server.started: self.policy_server.start() except error, ex: sys.stderr.write( 'FAILED to start flash policy server: %s\n' % (ex, )) except Exception: traceback.print_exc() sys.stderr.write('FAILED to start flash policy server.\n\n')