Search⌘ K
AI Features

Server and Client Constants

Explore how to centralize constant values for server and client configurations in gRPC Java applications. Understand the use of utility classes to manage settings like ports, directories, chunk sizes, and algorithms. This lesson helps you organize parameters to maintain code clarity and support server-client communication.

Constants are used to store information that does not change throughout the application’s lifecycle. We can define values or parameters related to the configuration and behavior of the server component of our application. Instead of scattering these constants throughout the codebase, they are centralized within a utility class.

Defining server constants

In the src/main/java/io/datajek/ftpservice/utils package, we will create a utility class named ServerConstants. This class will hold all constants used by the server. The class is shown below:

Java
public class ServerConstants {
private ServerConstants() {}
static public final String DESTINATION_DIRECTORY_ON_SERVER = "DESTINATION_DIRECTORY_ON_SERVER";
static public final int INSECURE_MODE_PORT = 17373;
static public final String TEMP_WRITE_PATH = "TEMP_WRITE_PATH";
static public final String LOCALHOST = "localhost";
}

The ...