8.4.2.2. pymodaq_utils.serialize.mysocket module

class pymodaq_utils.serialize.mysocket.Socket(socket=None)[source]

Bases: Socket

Custom Socket wrapping the built-in one and added functionalities to make sure message have been sent and received entirely

Methods

check_receiving(bytes_str)

First read the 4th first bytes to get the total message length Make sure to read that much bytes before processing the message

check_sended(data_bytes)

Make sure all bytes are sent through the socket :param data_bytes: :type data_bytes: bytes

check_sended_with_serializer(obj)

Convenience function to convert permitted objects to bytes and then use the check_sended method

check_receiving(bytes_str)[source]

First read the 4th first bytes to get the total message length Make sure to read that much bytes before processing the message

See check_sended and check_sended_with_serializer for a symmetric action

check_sended(data_bytes)[source]

Make sure all bytes are sent through the socket :param data_bytes: :type data_bytes: bytes

check_sended_with_serializer(obj)[source]

Convenience function to convert permitted objects to bytes and then use the check_sended method

Appends to bytes the length of the message to make sure the reception knows how much bytes to expect

For a list of allowed objects, see Serializer.to_bytes()

class pymodaq_utils.serialize.mysocket.SocketString(bytes_string)[source]

Bases: object

Mimic the Socket object but actually using a bytes string not a socket connection

Implements a minimal interface of two methods

Parameters:

bytes_string (bytes)

See also

Socket

Methods

check_received_length(length)

Make sure all bytes (length) that should be received are received through the socket.

get_first_nbytes(length)

Read the first N bytes from the socket

to_bytes

check_received_length(length)[source]

Make sure all bytes (length) that should be received are received through the socket.

Here just read the content of the underlying bytes string

Parameters:

length (int) – The number of bytes to be read from the socket

Return type:

bytes

get_first_nbytes(length)[source]

Read the first N bytes from the socket

Parameters:

length (int) – The number of bytes to be read from the socket

Returns:

the read bytes string

Return type:

bytes

to_bytes()[source]