Package de.craftsblock.craftsnet.api
Class Server
java.lang.Object
de.craftsblock.craftsnet.api.Server
- Direct Known Subclasses:
WebServer,WebSocketServer
Abstract class representing a server in the CraftsNet framework.
- Since:
- 3.0.3-SNAPSHOT
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidPerform necessary actions when the server is awakened or warn if needed.voidbind(int port) Binds the server to the specified port.voidbind(int port, int backlog) Binds the server to the specified port and backlog.intRetrieves the backlog size of the server.Retrieves the instance ofCraftsNetbound to the server.intgetPort()Retrieves the port number the server is bound to.booleanChecks if the server is enabled.booleanChecks if the server is running.booleanisSSL()Checks if SSL is enabled for the server.voidshouldUseSSL(boolean ssl) Sets whether SSL should be used for the server.abstract voidPuts the server to sleep if it is not needed.voidstart()Starts the server.voidstop()Stops the server.
-
Field Details
-
craftsNet
-
logger
-
port
protected int port -
backlog
protected int backlog -
ssl
protected boolean ssl -
running
protected boolean running
-
-
Constructor Details
-
Server
Constructs a server with the specified port and SSL configuration.- Parameters:
craftsNet- TheCraftsNetinstance which instantiates this server.port- The port number for the server.ssl- true if SSL should be used, false otherwise.
-
Server
Constructs a server with the specified port, backlog, and SSL configuration.- Parameters:
craftsNet- TheCraftsNetinstance which instantiates this server.port- The port number for the server.backlog- The maximum number of pending connections the server's socket may have in the queue.ssl- true if SSL should be used, false otherwise.
-
-
Method Details
-
bind
public void bind(int port) Binds the server to the specified port.- Parameters:
port- The port number to bind the server to.
-
bind
public void bind(int port, int backlog) Binds the server to the specified port and backlog.- 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.
-
shouldUseSSL
public void shouldUseSSL(boolean ssl) Sets whether SSL should be used for the server.- Parameters:
ssl-trueif SSL should be used,falseotherwise.
-
start
public void start()Starts the server. -
stop
public void stop()Stops the server. -
awakeOrWarn
public abstract void awakeOrWarn()Perform necessary actions when the server is awakened or warn if needed. -
sleepIfNotNeeded
public abstract void sleepIfNotNeeded()Puts the server to sleep if it is not needed. -
isEnabled
public boolean isEnabled()Checks if the server is enabled.- Returns:
- true if the server is enabled, false otherwise.
-
isRunning
public boolean isRunning()Checks if the server is running.- Returns:
- true if the server is running, false otherwise.
-
getPort
public int getPort()Retrieves the port number the server is bound to.- Returns:
- The port number of the server.
-
getBacklog
public int getBacklog()Retrieves the backlog size of the server.- Returns:
- The backlog size of the server.
-
isSSL
public boolean isSSL()Checks if SSL is enabled for the server.- Returns:
trueif SSL is enabled,falseotherwise.
-
getCraftsNet
Retrieves the instance ofCraftsNetbound to the server.- Returns:
- The instance of
CraftsNetbound to the server.
-