def check_received_length(sock, length):
    """
    Make sure all bytes (length) that should be received are received through the socket
    Parameters
    ----------
    sock
    length

    Returns
    -------

    """
    l = 0
    data_bytes = b''
    while l < length:
        if l < length - 4096:
            data_bytes_tmp = sock.recv(4096)
        else:
            data_bytes_tmp = sock.recv(length - l)
        l += len(data_bytes_tmp)
        data_bytes += data_bytes_tmp
    return data_bytes
