Question

I am writing a networked multi player game where players use their own client and server handles all the data processing...

I have finished writing for the game with one server.

What I want to do is, I will have a main server which will send information about different game rooms and players will be able to connect to the game room they want.

What I have in mind is if player click set up new game room, the client will tell server to set up new game which will create a new server and add the information about that server to the main server.

I am keeping secondary servers as ArrayList...

String line = in.nextLine();

if (line.equalsIgnoreCase("new game")) {
servers.add(new SecondaryServers(secondaryPort)); // starting secondary server
secondaryPort++; // this is to keep track of port number
System.out.println(i + " secondary server(s) started"); // printout in main server's console
 }

When I do it that way, it started a new server at the first time, but it never goes to the state to print out to the console.

Please help me out to create new servers from the main one :)

Was it helpful?

Solution

I think there is a ServerSocket.accept() method is called from within SecondaryServers. accept() is a blocking method so you should start SecondaryServers in a new Thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top