In this recipe, we'll look at the absolute minimum in order to get a server and client up and running and be able to talk to each other.
This is accomplished in just a few lines of code.
The server and client will share some common data that we'll store inside a properties
file for easy access and external modification. First and foremost, the client must know the address of the server, and both server and client need to know which port to listen on and connect to. These would most likely be editable from within a game.
Perform the following steps to set up a server and client:
In the constructor of the server class, we start by loading the properties file. Once done, we can initialize the server with the following lines of code:
server = Network.createServer(Integer.parseInt(prop.getProperty("server.port"))); server.start();
In the static block, we must also make sure that the server doesn't shut down immediately.
The client is set up in a similar...