Skip to content

Vertx Http Server

DodaTech 1 min read

In this tutorial, you'll learn about Fix Vert.x HTTP Server Not Starting. We cover key concepts, practical examples, and best practices.

The Problem

Vert.x HTTP server fails to start with bind errors or configuration issues.

Quick Fix

Use proper port

Wrong:

vertx.createHttpServer().listen(80);
// Port may be in use

Output:

BindException

Right:

vertx.createHttpServer().listen(8080);
// Use non-privileged port

Output:

Server starts successfully

Add request handler

Wrong:

vertx.createHttpServer().listen(8080);
// No request handler

Output:

404 for all requests

Right:

vertx.createHttpServer().requestHandler(req -> {
    req.response().end("Hello!");
}).listen(8080);

Output:

Handler registered

Handle errors asynchronously

Wrong:

vertx.createHttpServer().listen(8080);
// No error handler

Output:

Fail silently

Right:

vertx.createHttpServer().listen(8080)
    .onFailure(err -> log.error("Failed", err))
    .onSuccess(s -> log.info("Server started"));

Output:

Error handled

Prevention

  • Use a non-privileged port (above 1024) for development
  • Always set a request handler
  • Use onFailure/onSuccess callbacks for async error handling

Common Mistakes with http server

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world VERTX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does the server not respond to requests?

A request handler must be set with server.requestHandler().

This quick fix is part of the DodaTech Spring & JVM ecosystem series. Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro