Class WebServer

java.lang.Object
de.craftsblock.craftsnet.api.Server
de.craftsblock.craftsnet.api.http.WebServer

public class WebServer extends Server
The WebServer class represents a simple HTTP or HTTPS server that listens for incoming requests and handles them based on registered API endpoints using the provided RouteRegistry.
Since:
1.0.0-SNAPSHOT
See Also:
  • Constructor Details

    • WebServer

      public WebServer(CraftsNet craftsNet, int port, boolean ssl)
      Constructs a WebServer with the specified port and SSL settings.
      Parameters:
      craftsNet - The CraftsNet instance which instantiates this webserver.
      port - The port number to listen on.
      ssl - A boolean flag indicating whether SSL encryption should be used (true for HTTPS, false for HTTP).
  • Method Details

    • bind

      public void bind(int port, int backlog)
      Binds the server to the specified port and backlog.
      Overrides:
      bind in class Server
      Parameters:
      port - The port number to bind the server to.
      backlog - The maximum number of pending connections the server's socket may have in the queue.
    • start

      public void start()
      Starts the server.
      Overrides:
      start in class Server
    • stop

      public void stop()
      Stops the server.
      Overrides:
      stop in class Server
    • awakeOrWarn

      public void awakeOrWarn()
      Perform necessary actions when the server is awakened or warn if needed.
      Specified by:
      awakeOrWarn in class Server
    • sleepIfNotNeeded

      public void sleepIfNotNeeded()
      Puts the server to sleep if it is not needed.
      Specified by:
      sleepIfNotNeeded in class Server
    • isEnabled

      public boolean isEnabled()
      Checks if the server is enabled.
      Overrides:
      isEnabled in class Server
      Returns:
      true if the server is enabled, false otherwise.
    • isSSL

      public boolean isSSL()
      Checks if SSL is enabled for the server.
      Overrides:
      isSSL in class Server
      Returns:
      true if SSL is enabled, false otherwise.
    • shouldUseSSL

      public boolean shouldUseSSL()
      Checks if SSL should be enabled for the server.
      Returns:
      true if SSL should be enabled, false otherwise.