InetSocketAddress serverFast = new InetSocketAddress(InetAddress.getLocalHost(), 1501);
//client addresses
InetSocketAddress clientReliable = new InetSocketAddress(InetAddress.getLocalHost(), 0); //let Java choose a port for us
InetSocketAddress clientFast = new InetSocketAddress(InetAddress.getLocalHost(), 0); //let Java choose a port for us
//create the client and start it in its own thread
JGNClient client = new JGNClient(clientReliable, clientFast); //create the networking client
JGN.createThread(client).start(); //create a new thread for the client and start it
JMEGraphicalController controller = new JMEGraphicalController(); //in charge of generating and applying sync messages
//create the sync manager, register ourselves with it, and start its thread
SynchronizationManager syncManager = new SynchronizationManager(client, controller);
syncManager.addSyncObjectManager(this);
JGN.createThread(syncManager).start();
//get localSphere from the game
Field field = ExampleGame.class.getDeclaredField("localSphere");
field.setAccessible(true);
PlayerSphere player = null;
while((player = (PlayerSphere)field.get(app)) == null) {
try {
Thread.sleep(100);
}catch(Exception e) {
System.err.println("Error while thread sleeping to get field:");
e.printStackTrace();
}
}
//get rootNode from the game
field = ExampleGame.class.getDeclaredField("scene");
field.setAccessible(true);
Node scene = (Node)field.get(app);
setScene(scene);
//connect to the server
System.out.println("Connecting...");
client.connectAndWait(serverReliable, serverFast, 5000);
System.out.println("Connected!");
client.getServerConnection().getReliableClient().addMessageListener(new MessageListener() {
public void messageCertified(Message message) {
System.out.println("Message Certified: " + message);
}
public void messageFailed(Message message) {