GameServer.java
import java.net.*;
import java.io.*;
/**
Accept connection, send objects when asked.
*/
public class GameServer
{
public static void main(String[] argv)
{
String[] names = { // Names for server threads.
"Darling",
"Sweetheart",
"Honey",
};
int n = 0;
Object model = new GameWorld();
try {
// Set up a server socket.
ServerSocket serversock = new ServerSocket(8189);
while (true) {
// Wait for a connection.
Socket insock = serversock.accept();
// Spawn a thread to handle the connection.
MiniServer mini =
new MiniServer(names[n],insock,model);
Thread minithread = new Thread(mini);
minithread.start();
System.out.println("Started " + mini);
n++;
if (n >= names.length)
break;
}
// Clean up after handling all connections.
serversock.close();
}
catch(IOException ex) {
System.out.println(ex);
}
}
}