<!-- ** multithreaded http client and server

     $Id: sect_mt_http_client_server.docbook 754 2005-06-26 10:37:19Z ewald-arnold $
-->

<sect1 id="mt-http-client-server">
<title>Multithreaded &http; server </title>

<para>To create a multithreaded &http; server you need to create an according
server object with the number of desired threads. Then you start all the threads
and after maybe doing something useful you must wait for the termination of
all the threads.

<programlisting>

  TcpIpConnection conn (true, host, port);  <co id="mt-http-server-co" linkends="mt-http-server-link" />
  HttpProtocol prot(&amp;conn);
  HttpServer http_server (&amp;prot, num_threads);

  Dispatcher rpc_server;
  http_server.setRpcDispatcher(&amp;rpc_server);   <co id="mt-http-dispatcher-co" linkends="mt-http-dispatcher-link" />
  rpc_server.addMethod(&amp;testcall,
                        Struct::getValueName(),
                        "testcall",
                        Integer::getValueName() + "," + Integer::getValueName(),
                        "Testcase with a c-function");

  http_server.addHttpHandler("get",  <co id="mt-http-handler-co" linkends="mt-http-handler-link" />
                              make_methodhandler(rpcinfo,
                                                &amp;RpcInfoHandler::handler));
  http_server.addHttpHandler("post",
                              make_methodhandler(rpcinfo,
                                                &amp;RpcInfoHandler::handler));

  http_server.addRealm("/", "http-root-resource"); <co id="mt-http-realm-co" linkends="mt-http-realm-link" />
  http_server.addAuthentication("ali-baba",
                                "open-sesame",
                                "http-root-resource");

  http_server.addRealm("/RPC2", "rpc2-resource"); <co id="mt-rpc-realm-co" linkends="mt-rpc-realm-link" />
  http_server.addAuthentication("ali-baba-rpc",
                                "open-sesame-rpc",
                                "rpc2-resource");

  CppString root_dir = "/usr/local/ulxmlrpcpp/public_html";  <co id="mt-http-root-co" linkends="mt-http-root-link" />
  http_server.setHttpRoot(root_dir);

  unsigned started = http_server.runPicoHttpd();  <co id="mt-http-start-co" linkends="mt-http-start-link" />

  do_some_work(); <co id="mt-http-useful-co" linkends="mt-http-useful-link" />

  http_server.waitAsync(false, true); <co id="mt-http-term-co" linkends="mt-http-term-link" />

</programlisting>

<calloutlist>

 <callout arearefs="mt-http-server-co" id="mt-http-server-link">
  <para>Set up a connection and a server object.</para>
 </callout>

 <callout arearefs="mt-http-dispatcher-co" id="mt-http-dispatcher-link">
  <para>Set up the &xmlrpc; dispatcher which is handled by the &http; server.</para>
 </callout>

 <callout arearefs="mt-http-handler-co" id="mt-http-handler-link">
  <para>Add some handlers for requests to html resources.</para>
 </callout>

 <callout arearefs="mt-http-realm-co" id="mt-http-realm-link">
  <para>Add a realm and authentication data for the &http; resource.</para>
 </callout>

 <callout arearefs="mt-rpc-realm-co" id="mt-rpc-realm-link">
  <para>Add a realm and authentication data for the &xmlrpc; resource.</para>
 </callout>

 <callout arearefs="mt-http-root-co" id="mt-http-root-link">
  <para>Set the &http; root.</para>
 </callout>

 <callout arearefs="mt-http-start-co" id="mt-http-start-link">
  <para>Start the threads.</para>
 </callout>

 <callout arearefs="mt-http-useful-co" id="mt-http-useful-link">
  <para>Maybe do something other useful while the server threads respond to
  request.</para>
 </callout>

 <callout arearefs="mt-http-term-co" id="mt-http-term-link">
  <para>Wait for all the threads to terminate.</para>
 </callout>

</calloutlist>

</para>

</sect1>

