Package: weesocket
weesocketPython socket libraryAboutThis library is intended to be used as simple wrapper for working with python low level sockets.Installing weesocket# install weesocket library$pipinstallweesocket# dev version for development:$pipinstallweesocket[dev]# install developer requirementsUsingUse following objects as parents for your custom processing objects.ServerandClientobjects inheritsthreading.Threadmodule and works in thread mode.Server socket wrapperInitialize parameters:id- server identification name (type: str | default value:server)socket_file- unix socket file (type: str | default value:empty string)host- host ip (type: str | default value:empty string)port- host port (type: int | default value:0)buffer_size- buffer size for message receiver (type: int | default value:4096)proxy- specifying whether server can be used as proxy to send messages between clients (type: bool | default value:True)secret- secret to prove server identity (type: bytearray | default value:empty bytearray)remotes- list of client secrets to check their identities - (type: list of bytearrays | default value:empty list)encrypt- specifying whether encryption will be enabled (type: bool | default value:True)rsa_length- rsa key length - not used if keys given in parameters (type: int | default value:2048)public_key- private key string -generated if not given (type: str | default value:empty string)private_key- private key string - generated if not given (type: str | default value:empty string)daemon- variable specyfing if thread is daemonized (type: bool | default value:True)logger- python logger object (orNoneto disable logging) (type: logger | default value:None)Note: one of type parameterssocket_fileorhostandportmust be given, if both are given unix socket file is preferred.Remotes are not used if not given.Methods:send- disconnect from server (data:dict,target:str)disconnect- disconnect client from server (client_id:str)stop- stop server listening ()Note:targetparameter is optional, empty target is processed by server,*is intended to be used for broadcast to all other clients.Properties:id- id of connection | type:strenabled- status of connection | type:boolClient socket wrapperInitialize parameters:id- server identification name (type: str | default value:server)socket_file- unix socket file to connect (type: str | default value:empty string)host- server host ip to connect (type: str | default value:empty string)port- server host port to connect (type: int | default value:0)buffer_size- buffer size for message receiver (type: int | default value:4096)secret- secret code to prove identity (type: bytearray | default value:empty bytearray)remote_secret- secret code to check server identity (type: list of strings | default value:empty list)encrypt- specifying whether encryption will be enabled (type: bool | default value:True)rsa_length- rsa key length - not used if keys given in parameters (type: int | default value:2048)public_key- private key string -generated if not given (type: str | default value:empty string)private_key- private key string - generated if not given (type: str | default value:empty string)daemon- variable specyfing if thread is daemonized (type: bool | default value:True)logger- python logger object (orNoneto disable logging) (type: logger | default value:None)Note: one of type parameterssocket_fileorhostandportmust be given, if both are given unix socket file is preferred.Remotes are not used if not given.Methods:send- disconnect from server (data:dict,target:str)disconnect- disconnect from server ()Note:targetparameter is optional, empty target is processed by server,*is intended to be used for broadcast to all other clients and**is intended to be used for broadcast to all other clients and process by server.Properties:id- id of connection | type:strenabled- status of connection | type:boolExampleSimple examples of server and client socket wrappers.Server example:fromweesocketimportServerWrapperclassServerWrapper(Server):def_trigger(self,payload,sender):print("sender:",sender)print("payload:",payload)server=ServerWrapper(socket_file="/tmp/socket_file.sock")Client example:fromweesocketimportclientclassClientWrapper(Client):def_trigger(self,payload,sender):print("sender:",sender)print("payload:",payload)client=ClientWrapper(socket_file="/tmp/socket_file.sock")More examples intests folder.