Class WebServer
java.lang.Object
de.craftsblock.craftsnet.api.Server
de.craftsblock.craftsnet.api.http.WebServer
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:
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPerform necessary actions when the server is awakened or warn if needed.voidbind(int port, int backlog) Binds the server to the specified port and backlog.booleanChecks if the server is enabled.booleanisSSL()Checks if SSL is enabled for the server.booleanChecks if SSL should be enabled for the server.voidPuts the server to sleep if it is not needed.voidstart()Starts the server.voidstop()Stops the server.Methods inherited from class de.craftsblock.craftsnet.api.Server
bind, getBacklog, getCraftsNet, getPort, isRunning, shouldUseSSL
-
Constructor Details
-
WebServer
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. -
start
public void start()Starts the server. -
stop
public void stop()Stops the server. -
awakeOrWarn
public void awakeOrWarn()Perform necessary actions when the server is awakened or warn if needed.- Specified by:
awakeOrWarnin classServer
-
sleepIfNotNeeded
public void sleepIfNotNeeded()Puts the server to sleep if it is not needed.- Specified by:
sleepIfNotNeededin classServer
-
isEnabled
public boolean isEnabled()Checks if the server is enabled. -
isSSL
public boolean isSSL()Checks if SSL is enabled for the server. -
shouldUseSSL
public boolean shouldUseSSL()Checks if SSL should be enabled for the server.- Returns:
trueif SSL should be enabled,falseotherwise.
-