import socket
from typing import List


def receive_data(*, from_socket: socket.socket,
                 from_timeout=2) -> bytes:
    """
    Centralised fuction to handle receiving one or more packet buffers from TCP socket
    Args:
        from_socket:
            Socket sending stream to this instance.
        from_timeout:
            Set timeout for from_socket
    Returns:
            Complete binary stream from socket
    """
    from_socket.settimeout(from_timeout)
    fragments: List[bytes] = []
    try:
        stream = from_socket.recv(4096)
        fragments.append(stream)
        while True:
            if len(stream) < 4096:
                break
            else:
                stream = from_socket.recv(4096)
                fragments.append(stream)
    except TimeoutError:
        pass
    return b''.join(fragments)