Creating the Server (1)

The one thing that all multiplayer games need is a server, and this is no exception. So open up your IDE, and create a class called MTDServer, and extend AbstractSimpleGameServer.  You'll then probably need to add the particular import so it knows where to find it.  Also create the obligatory main() method to create a new instance of your new class.

Your code should look like this:-

import java.io.IOException;

import com.jme3.system.JmeContext;
import com.scs.stevetech1.entities.AbstractAvatar;
import com.scs.stevetech1.entities.AbstractServerAvatar;
import com.scs.stevetech1.server.AbstractSimpleGameServer;
import com.scs.stevetech1.server.ClientData;

public class MTDServer extends AbstractSimpleGameServer{


    public static void main(String[] args) {
        new MTDServer();
    }


    public MTDServer() {
       
    }

}


Unfortunately, that alone will not get you a running server.  You'll no doubt have lots of errors telling you that you need to create the abstract methods and the correct constructor.

The constructor for AbstractSimpleGameServer just takes a port number.  We'll use 6000.  it doesn't matter which port, as long as the client and server use the same one:-

    private MTDServer() throws IOException {
        super(6000);
        start(JmeContext.Type.Headless);

    }


Also, as in the code above, put code in to start the JME engine (as I'll call jMonkeyEngine from now on) once the constructor has run.

You will also need to create the abstract methods, but before we can fill these in, we need to create some new classes; in particular, some Entities, which are explained in the next section.


Comments