package echo;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Version 2: a thread per client. The main thread only accepts connections.
 */
public class ThreadedEchoServer {

	public static void main ( String[] args ) throws IOException {
		ServerSocket server = new ServerSocket(EchoServer.PORT);
		System.out
		    .println("threaded echo server listening on port " + EchoServer.PORT);

		int count = 0;
		for ( ; true ; ) {
			Socket socket = server.accept();
			count++;
			Thread thread = new Thread(new EchoHandler(socket),"client-" + count);
			thread.start(); // and straight back to accept()
		}
	}

}
