socketio.server

This is the component used to hook Gevent and its WSGI server to the WSGI app to be served, while dispatching any Socket.IO related activities to the handler and the transports.

class socketio.server.SocketIOServer(*args, **kwargs)[source]

Bases: WSGIServer

A WSGI Server with a resource that acts like an SocketIO.

__init__(*args, **kwargs)[source]

This is just like the standard WSGIServer __init__, except with a few additional kwargs:

Parameters:
  • resource – The URL which has to be identified as a socket.io request. Defaults to the /socket.io/ URL.

  • transports – Optional list of transports to allow. List of strings, each string should be one of handler.SocketIOHandler.handler_types.

  • policy_server – Boolean describing whether or not to use the Flash policy server. Default True.

  • 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

  • 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.

  • 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.

  • 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.

  • 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).

get_socket(sessid='')[source]

Return an existing or new client Socket.

handle(socket, address)[source]

Create an instance of handler_class to handle the request.

This method blocks until the handler returns.

start_accepting()[source]
stop(timeout=None)[source]

Stop accepting the connections and close the listening socket.

If the server uses a pool to spawn the requests, then stop() also waits for all the handlers to exit. If there are still handlers executing after timeout has expired (default 1 second, stop_timeout), then the currently running handlers in the pool are killed.

If the server does not use a pool, then this merely stops accepting connections; any spawned greenlets that are handling requests continue running until they naturally complete.