<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def send(self, command, sender, target, args, kwargs):
 """Used by the server to send messages to the client. Returns a future. """

        command = get_command(command)
        data = {'command': command.__name__,
                'id': create_aid(),
                'sender': actor_identity(sender),
                'target': actor_identity(target),
                'args': args if args is not None else (),
                'kwargs': kwargs if kwargs is not None else {}}

        waiter = self._loop.create_future()
        ack = None
        if command.ack:
            ack = create_aid()
            data['ack'] = ack
            self.pending_responses[ack] = waiter

        try:
            self.write(data)
        except Exception as exc:
            waiter.set_exception(exc)
            if ack:
                self.pending_responses.pop(ack, None)
        else:
            if not ack:
                waiter.set_result(None)
        return waiter