Creating the Server (1)
The first thing that our game will need is a server. This is the master program that will keep track of the game and send data to all the clients telling them what to show.
So open up your IDE, and create a class called MTDServer, and extend
AbstractSimpleGameServer. You'll then probably need to add the relevant imports 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);
}
Ports must be typically between 1025 and 65535, and if you're going to play this over a network, the usual firewall settings will apply.
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 missing 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.
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);
}
Ports must be typically between 1025 and 65535, and if you're going to play this over a network, the usual firewall settings will apply.
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 missing 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
Post a Comment