FileDocCategorySizeDatePackage
EchoServerThreaded2.javaAPI DocExample2256Sat Mar 13 15:40:06 GMT 2004None

EchoServerThreaded2

public class EchoServerThreaded2 extends Object
Threaded Echo Server, pre-allocation scheme. Each Thread waits in its accept() call for a connection; this synchronizes on the serversocket when calling its accept() method.
author
Ian F. Darwin.

Fields Summary
public static final int
ECHOPORT
public static final int
NUM_THREADS
Constructors Summary
public EchoServerThreaded2(int port, int numThreads)
Constructor

		ServerSocket servSock;
		Socket clientSocket;

		try {
			servSock = new ServerSocket(ECHOPORT);
		
		} catch(IOException e) {
			/* Crash the server if IO fails. Something bad has happened */
			throw new RuntimeException("Could not create ServerSocket " + e);
		}

		// Create a series of threads and start them.
		for (int i=0; i<numThreads; i++) {
			new Handler(servSock, i).start();
		}
	
Methods Summary
public static voidmain(java.lang.String[] av)
Main method, to start the servers.


	       
	    
	
		new EchoServerThreaded2(ECHOPORT, NUM_THREADS);