Hi @all,
I decided to go multiplayer with my little project and read the tutorials about SpiderMonkey.
When I start the client without server being started, it fails; so far so good.
But when I start the client after the server was started, it doesn´t really connect, but simply does… nothing at all.
This is my Server:
[java]
public class NetworkManager implements ConnectionListener {
private Main m;
private Server server;
private ServerListener listener;
public NetworkManager(Main m) {this.m=m;}
public void init() {
try {server = Network.createServer(6143);server.addConnectionListener(this);
} catch (IOException ex) {Logger.getLogger(NetworkManager.class.getName()).log(Level.SEVERE, null, ex);}
registerMessages();
server.start();
}
private void registerMessages() {
listener = new ServerListener();
Serializer.registerClass(LoginMessage.class);
server.addMessageListener(listener,LoginMessage.class);
}
public void stop() {
while (server.getConnections().size()>0) {server.getConnection(0).close("Server is shutting down.");}
server.close();
}
public void connectionAdded(Server server, HostedConnection conn) {
System.out.println("CONNNNNNNNNECTION!!!");
}
public void connectionRemoved(Server server, HostedConnection conn) {}
}
[/java]
And this is my Client:
[java]
public class NetworkManager implements ClientStateListener {
private Main m;
private Client client;
public NetworkManager(Main m) {this.m=m;}
public void init() {registerMessages();}
private void registerMessages() {
Serializer.registerClass(LoginMessage.class);
}
public void connect() {
try {client = Network.connectToServer("localhost",6143);client.addClientStateListener(this);System.out.println("test");
} catch (IOException ex) {Logger.getLogger(NetworkManager.class.getName()).log(Level.SEVERE, null, ex);}
}
public void stop() {client.close();}
public void clientConnected(Client c) {
System.out.println("connected");
Message message = new LoginMessage(m.getName());
if (client.isConnected()) {client.send(message);}
m.launchWorld();
}
public void clientDisconnected(Client c, DisconnectInfo info) {m.stop();System.exit(0);}
}
[/java]
When I call “connect()” on the Client, “test” gets printed, as to be excpected.
But neither the Server nor the Client is calling “connectionAdded(…)” or respectiveley “clientConnected(…)”.
I hope it´s just a basic misunderstanding somewhere.
Thanks in advance!