Book Image

JMonkeyEngine 3.0 Cookbook

By : Rickard Eden
Book Image

JMonkeyEngine 3.0 Cookbook

By: Rickard Eden

Overview of this book

Table of Contents (17 chapters)
jMonkeyEngine 3.0 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Setting up a server and client


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.

How to do it...

Perform the following steps to set up a server and client:

  1. 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.

  2. The client is set up in a similar...