module documentation

File containing functions for communication with Socket !

Function create_socket_server Everything in the title
Function data_to_dict Convert a string representing a JSON to a JSON
Function dict_to_packet Convert dict to packet
Function receive_data Receive msg which cannot be contained in only one buffer
Function receive_dict Receive json through a Socket
Function receive_dict_w_payload Receive json through a Socket then extract payload content. Payload can typically be an heavy file like an image
def create_socket_server(ip_address, port) -> socket.socket:

Everything in the title

Parameters
ip_addressIP Address
portPort
Returns
socket.socketSocket object
def data_to_dict(data) -> Optional[dict]:

Convert a string representing a JSON to a JSON

Parameters
dataString representing a JSON
Returns
Optional[dict]dict of this JSON
def dict_to_packet(dict_obj, packet_size_infos=DEFAULT_PACKET_SIZE_INFOS) -> bytes:

Convert dict to packet

Parameters
dict_obj:dictUndocumented
packet_size_infos
Returns
bytespacket
def receive_data(sckt, packet_size_infos, buffer_size) -> Optional[str]:

Receive msg which cannot be contained in only one buffer

Parameters
scktthe socket
packet_size_infosFormat de l'objet du message : permet de savoir sur cb de bytes est codee la taille
buffer_sizebuffer size for reading socket's buffer
Returns
Optional[str]Bytes corresponding to received packet !
def receive_dict(sckt, packet_size_infos=DEFAULT_PACKET_SIZE_INFOS, buffer_size=READ_SIZE) -> dict:

Receive json through a Socket

Parameters
scktthe socket
packet_size_infosFormat de l'objet du message : permet de savoir sur cb de bytes est codee la taille
buffer_sizebuffer size for reading socket's buffer
Returns
dict
def receive_dict_w_payload(sckt, packet_size_infos=DEFAULT_PACKET_SIZE_INFOS, buffer_size=READ_SIZE) -> (dict, bytes):

Receive json through a Socket then extract payload content. Payload can typically be an heavy file like an image

Parameters
scktthe socket
packet_size_infosFormat de l'objet du message : permet de savoir sur cb de bytes est codee la taille
buffer_sizebuffer size for reading socket's buffer
Returns
(dict, bytes)dict of packet's JSON, payload