Client#

class socketsc.SocketClient#

The socket client class.

Parameters
  • address – A tuple with the address and port of the server.

  • address_family – The address family to use (socketsc.socket.AF_INET or socketsc.AF_INET6)

  • sock_type – The socket type to use (Only socketsc.SOCK_TCP is supported at the moment)

Variables

connected – A boolean indicating if the client is connected to the server.

Returns

A SocketClient object.

connect()#

Connect to the server and start listening for incoming messages.

on(event, callback)#

Register a callback for an event.

Parameters
  • event (str) – The event to listen for.

  • callback (Callable[SocketClient, Any]) – The callback to call when the event is received.

emit(event, data=None)#

Emit an event to the server.

Parameters
  • event (str) – The event to emit.

  • data (Any) – The data to send.

remove_listener(event, callback)#

Remove a listener for a specific event

Parameters
  • event (str) – The event to remove the listener for

  • callback (Callable[SocketClient, Any]) – The callback to remove

remove_all_listeners(event)#

Remove all listeners for a specific event

Parameters

event (str) – The event to remove all listeners for

shutdown(__how)#

Shutdown the socket.

Parameters

__how (int) – The shutdown mode. See Address Family for more information.

close()#

Close the socket.