Class socketio.manager
socket.io manager class, handling an active connection with a server.
Handlers of the engine.io protocol - being the transport protocol, the layer under the socket.io protocol - is defined here. The manager is responsible of the negotiation with the server of the transport to use, and making sure the connection is still active. Sockets for given paths/namespaces can be instantiated here thanks to the method socketio.manager.socket to actually interact with the server.
Functions
H.open (self, pkt) | Called when a packet 'OPEN' is received |
H.close (self, pkt) | Called when a packet 'CLOSE' is received |
H.ping (self, pkt) | Called when a packet 'PING' is received |
H.pong (self, pkt) | Called when a packet 'PONG' is received |
H.message (self, pkt) | Called when a packet 'MESSAGE' is received |
C.new (url, opts) | Class constructor. |
Methods
socketio.manager:on (self, name, func) | Registers or unregisters an callback to a given event |
socketio.manager:packet (self, pkt) | Send a packet to the server. |
socketio.manager:open (self) | Open the transport. |
socketio.manager:close (self) | Close the manager. |
socketio.manager:reconnect (self) | Reconnect to the server (close and open back). |
socketio.manager:socket (self, path) | Returns a socket instance for a given path. |
Functions
- H.open (self, pkt)
-
Called when a packet 'OPEN' is received
Parameters:
- self instance of socketio.manager.
- pkt Packet 'OPEN'.
- H.close (self, pkt)
-
Called when a packet 'CLOSE' is received
Parameters:
- self instance of socketio.manager.
- pkt Packet 'CLOSE'
- H.ping (self, pkt)
-
Called when a packet 'PING' is received
Parameters:
- self instance of socketio.manager.
- pkt Packet 'PING'
- H.pong (self, pkt)
-
Called when a packet 'PONG' is received
Parameters:
- self instance of socketio.manager.
- pkt Packet 'PONG'
- H.message (self, pkt)
-
Called when a packet 'MESSAGE' is received
Parameters:
- self instance of socketio.manager.
- pkt Packet 'MESSAGE'
- C.new (url, opts)
-
Class constructor.
Parameters:
- url socket.io URL.
- opts Global options, that sockets and transports will inherit.
- reconnection_delay Time in seconds to wait before attempting a reonnection to the server. Default value is 1s.
- reconnection_delay_max Maximum time in seconds to wait before attempting a reconnection to the server. Default value is 5s.
- randomization_factor Random factor to apply to time to wait before reconnection (jitter). Default value is 50%.
- proxy If defined, URL to HTTP proxy to use. Default value is nil.
- auto_connect If true, automatically connect a socket when instantiated. Default value is true.
Returns:
-
An instance of socketio.manager.
Methods
- socketio.manager:on (self, name, func)
-
Registers or unregisters an callback to a given event
Parameters:
- self instance of socketio.manager.
- name An event name
- func The function to link to the event if defined. 'nil' would mean to unregister a previous registered function.
- socketio.manager:packet (self, pkt)
-
Send a packet to the server.
Parameters:
- self instance of socketio.manager.
- pkt The packet to be sent.
- socketio.manager:open (self)
-
Open the transport. A connection will be opened to the server. When the
manager is effectively opened, the event 'open' will be fired.
Parameters:
- self instance of socketio.manager.
- socketio.manager:close (self)
-
Close the manager. This closes the current session, if defined, and the
connection with the server, if existed.
Parameters:
- self instance of socketio.manager.
- socketio.manager:reconnect (self)
-
Reconnect to the server (close and open back).
Parameters:
- self instance of socketio.manager.
- socketio.manager:socket (self, path)
-
Returns a socket instance for a given path. If no socket for a given path
exists, one socket is instantiated, registered and returned. Socket is
automatically connected to the path if the option 'auto_connect' is true.
Parameters:
- self instance of socketio.manager.
- path Path of the socket to get.
Returns:
-
Instance of socketio.socket.