Class Server

java.lang.Object
de.craftsblock.craftsnet.api.Server
Direct Known Subclasses:
WebServer, WebSocketServer

public abstract class Server extends Object
Abstract class representing a server in the CraftsNet framework.
Since:
3.0.3-SNAPSHOT
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
    protected final CraftsNet
     
    protected final Logger
     
    protected int
     
    protected boolean
     
    protected boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Server(CraftsNet craftsNet, int port, boolean ssl)
    Constructs a server with the specified port and SSL configuration.
    Server(CraftsNet craftsNet, int port, int backlog, boolean ssl)
    Constructs a server with the specified port, backlog, and SSL configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Perform necessary actions when the server is awakened or warn if needed.
    void
    bind(int port)
    Binds the server to the specified port.
    void
    bind(int port, int backlog)
    Binds the server to the specified port and backlog.
    int
    Retrieves the backlog size of the server.
    Retrieves the instance of CraftsNet bound to the server.
    int
    Retrieves the port number the server is bound to.
    boolean
    Checks if the server is enabled.
    boolean
    Checks if the server is running.
    boolean
    Checks if SSL is enabled for the server.
    void
    shouldUseSSL(boolean ssl)
    Sets whether SSL should be used for the server.
    abstract void
    Puts the server to sleep if it is not needed.
    void
    Starts the server.
    void
    Stops the server.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • craftsNet

      protected final CraftsNet craftsNet
    • logger

      protected final Logger logger
    • port

      protected int port
    • backlog

      protected int backlog
    • ssl

      protected boolean ssl
    • running

      protected boolean running
  • Constructor Details

    • Server

      public Server(CraftsNet craftsNet, int port, boolean ssl)
      Constructs a server with the specified port and SSL configuration.
      Parameters:
      craftsNet - The CraftsNet instance which instantiates this server.
      port - The port number for the server.
      ssl - true if SSL should be used, false otherwise.
    • Server

      public Server(CraftsNet craftsNet, int port, int backlog, boolean ssl)
      Constructs a server with the specified port, backlog, and SSL configuration.
      Parameters:
      craftsNet - The CraftsNet instance 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 - true if SSL should be used, false otherwise.
    • 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:
      true if SSL is enabled, false otherwise.
    • getCraftsNet

      public CraftsNet getCraftsNet()
      Retrieves the instance of CraftsNet bound to the server.
      Returns:
      The instance of CraftsNet bound to the server.