Boost logo

Boost :

From: JD (jean.daniel.michaud_at_[hidden])
Date: 2007-08-13 14:39:24

Ariel Kalingking wrote:
> Hi,
> I am looking for a similar functionality and would like to ask your
> opinion, what would it require to make cli usable across a network?
> For example I would want to embed it and control an existing
> application using a telnet like service.

Well I guess for that you would need much more than a CLI. But you can
use it in conjunction with some RPC implementation like xml-rpc
(, and bind the cli commands to an
XmlRpcClient that would call remote procedure on XmlRpcServer.

Something like that:

// Code on client side:
#define PORT 16000

void sendFile(std::vector<std::string> &args)
   XmlRpcClient c(argv[0], PORT);
   XmlRpcValue server_args, result;
   server_args.setSize(args.size() - 1);
   for (int i = 1; i < args.size(); ++i) server_args[i] = args[i];
   if (c.execute("send_file", server_args, result))
     std::cout << "\nMethods:\n " << result << "\n\n";
     std::cout << "Error calling 'listMethods'\n\n";

int main(int argc, char **argv)
   boost::cli::commands_description desc;
     ("sendFile", po::value< std::vector<std::string>
>()->notifier(&sendFile), "SendFile <server_ip_address> <file1> ...

   boost::cli::command_line_interpreter cli(desc, ">");

//Code on server side:
// No arguments, result is "Hello".
class SendFile : public XmlRpcServerMethod
   SendFile(XmlRpcServer* s) : XmlRpcServerMethod("send_file", s) {}

   void execute(XmlRpcValue& params, XmlRpcValue& result)
     std::cout << "send_file called on server" << std::endl;
     // Sends the files in params here!

int main(int argc, char **argv)
   XmlRpcServer s;
   SendFile sf_command(&s);;
   return 0;

Don't forget to use the last version of the cli on ! :)


Boost list run by bdawes at, gregod at, cpdaniel at, john at