Example usage for io.vertx.core.http HttpServer listen

List of usage examples for io.vertx.core.http HttpServer listen

Introduction

In this page you can find the example usage for io.vertx.core.http HttpServer listen.

Prototype

Future<HttpServer> listen();

Source Link

Document

Tell the server to start listening.

Usage

From source file:examples.HTTPExamples.java

License:Open Source License

public void example3(Vertx vertx) {

    HttpServer server = vertx.createHttpServer();
    server.listen();
}

From source file:net.sf.sgsimulator.sgsrest.SGSVertxServer.java

License:Open Source License

public static void main(String[] args) throws Exception {
    String configFile = null;/* w w w  .j  a  v  a  2s .co m*/
    if (args.length == 0) {
        configFile = "config.json";
    } else {
        configFile = args[0];
    }

    Path configPath = Paths.get(configFile);
    JsonObject config = new JsonObject(new String(Files.readAllBytes(configPath)));

    Random r = new Random(new Date().getTime());
    char c1 = (char) (r.nextInt(26) + 'a');
    char c2 = (char) (r.nextInt(26) + 'a');
    char c3 = (char) (r.nextInt(26) + 'a');
    String admincode = "" + c1 + c2 + c3;
    System.getProperties().put("sgsimulator.admincode", admincode);

    Vertx vertx = Vertx.vertx();
    System.out.println("****************************");
    System.out.println("Starting...");
    System.out.println("To load pages:");
    System.out.println(
            "http://" + config.getString("host") + ":" + config.getInteger("port") + "/sg/pages/panel");
    System.out.println("Admin interface (only allowed from " + config.getString("adminip") + ":");
    System.out.println("http://" + config.getString("host") + ":" + config.getInteger("port")
            + "/sg/pages/admin/" + admincode);
    System.out.println("Projector screen interface (only allowed from " + config.getString("adminip") + ":");
    System.out.println(
            "http://" + config.getString("host") + ":" + config.getInteger("port") + "/sg/pages/screen");

    System.out.println("****************************");

    VertxNubes nubes = new VertxNubes(vertx, config);

    // System.err.println("IP:"+ip.substring(1));

    // config.put("host", ip.substring(1));
    System.getProperties().put("sgsimulator.scenario", config.getJsonObject("gridlab").getString("scenario"));
    System.getProperties().put("sgsimulator.adminip", config.getString("adminip"));
    nubes.bootstrap(res -> {
        if (res.succeeded()) {
            final Router router = res.result();
            final HttpServer server = vertx.createHttpServer(new HttpServerOptions(config));
            server.requestHandler(router::accept);
            server.listen();
            System.out.println("****************************");
            System.out.println("Started...");
            System.out.println("****************************");
        } else {
            res.cause().printStackTrace();
        }
    });
    // nubes.stop((_void) -> {
    // vertx.close();
    // });
}