def METHOD_NAME() -> int:
    messages_received: int = 0
    with grpc_connection(server_address=f"[::]:{port}") as conn:
        receive, send, _, _ = conn
        # Setup processing loop
        while True:
            # Block until server responds with a message
            task_ins = receive()
            if task_ins is None:
                raise ValueError("Unexpected None value")
            # pylint: disable=no-member
            if task_ins.HasField("task") and task_ins.task.HasField(
                "legacy_server_message"
            ):
                server_message = task_ins.task.legacy_server_message
            else:
                server_message = None
            # pylint: enable=no-member
            if server_message is None:
                raise ValueError("Unexpected None value")
            messages_received += 1
            if server_message.HasField("reconnect_ins"):
                task_res = TaskRes(
                    task=Task(legacy_client_message=CLIENT_MESSAGE_DISCONNECT)
                )
                send(task_res)
                break
            # Process server_message and send client_message...
            task_res = TaskRes(task=Task(legacy_client_message=CLIENT_MESSAGE))
            send(task_res)
    return messages_received