I succesfully tested basic messaging between 1 server and 2,3… clients that performed as expected. But when I start a server on Amazon (ubuntu) then it doesn’t connect. Could you please help me how I can enable the routing or ports so that the client connects to the server? I based my code on the monkeyzone example. but my execution stops at myClient.send but why? I used com.jme3.network.Client and com.jme3.network.ClientStateListenerfor a multiplayer gaming server project (that worked locally in a LAN setting). Then I started a server on aws and tried to connect but the client times out without a stacktrace. What can be done? The client connect code is
[java] try {
System.out.println("connecting to "+serverName);
myClient = Network.connectToServer(serverName, portNumber);
System.out.println("connected to "+serverName);
Serializer.registerClass(ActionMessage.class);
myClient.addMessageListener(new ClientListener(app, myClient), ActionMessage.class);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (myClient != null) {
myClient.start();
myClient.addClientStateListener(app);
} else {
System.out.println("myClient == null "+serverName);
}[/java]
The server is
[java]
import java.io.IOException;
import com.jme3.app.SimpleApplication;
import com.jme3.system.JmeContext;
import com.jme3.network.ConnectionListener;
import com.jme3.network.Filters;
import com.jme3.network.HostedConnection;
import com.jme3.network.Message;
import com.jme3.network.Network;
import com.jme3.network.Server;
import com.jme3.network.serializing.Serializer;
public class SpaceWorldServer extends SimpleApplication implements
ConnectionListener {
Server myServer = null;
public static void main(String[] args) {
System.out.println("main SpaceWorldServer");
SpaceWorldServer app = new SpaceWorldServer();
app.start(JmeContext.Type.Headless);
}
public void simpleInitApp() {
System.out.println("simpleInitApp");
try {
myServer = Network.createServer(6143);
Serializer.registerClass(ActionMessage.class);
myServer.addMessageListener(new ServerListener(),
ActionMessage.class);
myServer.addConnectionListener(this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
myServer.start();
}
@Override
public void destroy() {
// custom code
myServer.close();
super.destroy();
}
public void connectionAdded(Server s, HostedConnection c) {
System.out.println("connectionAdded:" + c.toString());
Message message = new ActionMessage(100, 200, true);
System.out.println("broadcasting message " + message.toString());
myServer.broadcast(Filters.notEqualTo(c), message);
System.out.println("broadcast message " + message.toString());
}
public void connectionRemoved(Server s, HostedConnection c) {
}
int counter = 0;
@Override
public void simpleUpdate(float tpf) {
if (counter != myServer.getConnections().size()) {
System.out.println("#connections:"
+ myServer.getConnections().size());
counter = myServer.getConnections().size();
}
}
}[/java]
In my home LAN, I can start 1 server on 1 physical machine and 1 client on the same machine and then starting a client on a different computer in the LAN will trigger events and rending at the other client, but this won’t work with the server on aws.amazon.com. Why not?
[java]public class ClientListener implements ClientStateListener,
MessageListener<Client> {
private UFOSpaceWorld app;
private Client client;
public ClientListener(UFOSpaceWorld app, Client client) {
this.app = app;
this.client = client;
client.addClientStateListener(this);
client.addMessageListener(this, ActionMessage.class);
}
public void messageReceived(Client source, Message message) {
if (message instanceof ActionMessage) {
// do something with the message
ActionMessage helloMessage = (ActionMessage) message;
System.out.println("Client #" + source.getId() + " received: '"
+ helloMessage.toString() + "'");
System.out.println("getAction #" + helloMessage.getAction());
System.out.println("DRAWING NEW OTO: '" + helloMessage.toString()
+ "'");
if (helloMessage.getAction() == 200) {
System.out.println(" NEW OTOs AND SAUCERS");
app.enqueue(new Callable<Void>() {
public Void call() throws Exception {
app.createNewOtoBot();
app.addNewSaucer();
System.out.println("CREATED NEW OTOs AND SAUCERS");
return null;
}
});
}
}
}
@Override
public void clientConnected(Client arg0) {
// TODO Auto-generated method stub
System.out.println("clientConnected");
}
@Override
public void clientDisconnected(Client arg0, DisconnectInfo arg1) {
// TODO Auto-generated method stub
System.out.println("clientDisconnected");
}
}[/java]