Multiplayer works in home LAN but not with server on aws?

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&lt;Void&gt;() {
				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]

firewall?

1 Like
@normen said: firewall?
I turned off my MCAffe firewall locally and opened the port at amazon. I read some other posts that port forwading might be needed, but I'm not sure why. In my hom LAN the client connects and registers with the local server as expected:

[java]connecting to localhost
connected to localhost
clientConnected
clientConnected
Number of Collisions betweenModels/Saucer/usaucer_v01.blend and Models/JumpGate/
JumpGate.blend: 225268
What was hit? Sphere.0371
Where was it hit? null
Distance? 0.0
Warped
sending message spaceworld.ActionMessage@21162f63
sent message spaceworld.ActionMessage@21162f63[/java]

But trying to connect with server on amazon, then it stops. (ipv4 port 6143) Perhaps I should also turn off some builtin Windows firewall?

Port forwarding is only needed when you run the server in your local network and want to make it available from the internet, because the router is the actual node thats connected to the internet it would have to forward the request to your computer in the local net. Idk exactly how these amazon servers work but I think they should be directly connected to the internet, so you probably don’t need forwarding there. Maybe make sure its the right port type you opened (TCP/UDP)

1 Like
@normen said: Port forwarding is only needed when you run the server in your local network and want to make it available from the internet, because the router is the actual node thats connected to the internet it would have to forward the request to your computer in the local net. Idk exactly how these amazon servers work but I think they should be directly connected to the internet, so you probably don't need forwarding there. Maybe make sure its the right port type you opened (TCP/UDP)

Thank you very much for the information. I opened also UDP (in addition to TCP) on amazon and now it connects and the message is sent!

[java]connecting to 54.72.176.8
connected to 54.72.176.8
clientConnected
clientConnected
Number of Collisions betweenModels/Saucer/usaucer_v01.blend and Models/JumpGate/
JumpGate.blend: 225268
What was hit? Sphere.0371
Where was it hit? null
Distance? 0.0
Warped
sending message spaceworld.ActionMessage@54a63aad
sent message spaceworld.ActionMessage@54a63aad[/java]

And the server logs that it happened:
[java]
connectionAdded:Connection[ id=3, reliable=NioEndpoint[4, java.nio.channels.SocketChannel[connected local=/172.31.29.63:6143 remote=/213.89.131.6:12400]], fast=UdpEndpoint[1, /213.89.131.6:58814] ]
broadcasting message spaceworld.ActionMessage@3447c30b
broadcast message spaceworld.ActionMessage@3447c30b
#connections:1
Server received ‘spaceworld.ActionMessage@55c59c26’ from client #3

[/java]

:slight_smile:

Ha! People here really know their stuff.

2 Likes