import java.net.*;
import java.io.*;
import java.util.*;
public class BroadcastEchoServer {
static protected Set activeClients = new HashSet();
public static void main(String args[]) {
int id = 1;
int port;
ServerSocket server_socket;
try {
port = Integer.parseInt(args[0]);
}
catch (Exception e) {
System.out.println("port = 4001 (default)");
port = 4001;
}
try {
server_socket = new ServerSocket(port);
System.out.println("Server waiting for client on port " +
server_socket.getLocalPort());
// server infinite loop
while(true) {
Socket socket = server_socket.accept();
System.out.println("New connection accepted " + socket.getInetAddress() + ":" + socket.getPort());
BroadcastClientHandler newClient = new BroadcastClientHandler(socket, id++);
activeClients.add(newClient);
newClient.start();
}
}
catch (IOException ioe) {
}
}
}