File: servers.C

package info (click to toggle)
witty 3.3.3%2Bdfsg-4.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 28,228 kB
  • ctags: 26,694
  • sloc: cpp: 147,809; ansic: 77,999; xml: 16,331; sh: 1,303; makefile: 198; java: 86; sql: 14
file content (67 lines) | stat: -rw-r--r-- 1,702 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */

#include <iostream>

#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WEnvironment>
#include <Wt/WText>
#include <Wt/WServer>

using namespace Wt;

WApplication *createApplication(const WEnvironment& env)
{
  WApplication *app = new WApplication(env);
  app->setTitle("Multiple servers @ " + env.hostName());
  app->root()->addWidget(new WText("Well hello there"));

  return app;
}

int main(int, char **)
{
  try {
    int argc = 5;
    char** argv1 = new char*[argc];

    argv1[0] = (char *) "multiple";
    argv1[1] = (char *) "--http-address=0.0.0.0";
    argv1[2] = (char *) "--http-port=8080";
    argv1[3] = (char *) "--deploy-path=/";
    argv1[4] = (char *) "--docroot=.";

    WServer server1(argv1[0]);
    server1.setServerConfiguration(argc, argv1, WTHTTP_CONFIGURATION);

    char** argv2 = new char*[argc];

    argv2[0] = (char *) "multiple";
    argv2[1] = (char *) "--http-address=0.0.0.0";
    argv2[2] = (char *) "--http-port=7070";
    argv2[3] = (char *) "--deploy-path=/";
    argv2[4] = (char *) "--docroot=.";

    WServer server2(argv2[0]);
    server2.setServerConfiguration(argc, argv2, WTHTTP_CONFIGURATION);

    server1.addEntryPoint(Application, createApplication);
    server2.addEntryPoint(Application, createApplication);

    if (server1.start()) {
      if (server2.start()) {
	WServer::waitForShutdown();
	server2.stop();
      }
      server1.stop();
    }
  } catch (Wt::WServer::Exception& e) {
    std::cerr << e.what() << std::endl;
  } catch (std::exception &e) {
    std::cerr << "exception: " << e.what() << std::endl;
  }
}