serve method

Future<RelicServer> serve({
  1. InternetAddress? address,
  2. int port = 8080,
  3. SecurityContext? securityContext,
  4. int backlog = 0,
  5. bool v6Only = false,
  6. bool shared = false,
  7. int noOfIsolates = 1,
})

Starts a HttpServer that listens on the specified address and port and sends requests to handler.

If securityContext is provided, a secure HTTPS server will be started using HttpServer.bindSecure. Otherwise, an HTTP server will be started using HttpServer.bind.

The maximum length of the queue for incoming connections is specified by backlog. Defaults to 0 (system-dependent)

The v6Only parameter controls whether an IPv6 socket accepts only IPv6 connections (ignored for IPv4 addresses).

The noOfIsolates parameter specifies the number of isolates to spawn for handling requests. When greater than 1, shared is automatically enabled to allow multiple isolates to bind to the same port.

If not specified address will default to InternetAddress.loopbackIPv4, and port to 8080.

Implementation

Future<RelicServer> serve({
  final InternetAddress? address,
  final int port = 8080,
  final SecurityContext? securityContext,
  final int backlog = 0,
  final bool v6Only = false,
  final bool shared = false,
  final int noOfIsolates = 1,
}) {
  return run(
    () => IOAdapter.bind(
      address ?? InternetAddress.loopbackIPv4,
      port: port,
      context: securityContext,
      backlog: backlog,
      v6Only: v6Only,
      shared: shared || noOfIsolates > 1,
    ),
    noOfIsolates: noOfIsolates,
  );
}