packageSocket;importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.IOException;importjava.io.InputStreamReader;importjava.io.OutputStreamWriter;importjava.io.PrintWriter;importjava.net.InetAddress;importjava.net.Socket;class JabberClientThread extendsThread {privateSocket socket;privateBufferedReader in;privatePrintWriter out;private static int counter = 0;private int id = counter++;private static int threadcount = 0;public static intthreadCount() {returnthreadcount;
}publicJabberClientThread(InetAddress addr) {
System.out.println("Making client " +id);
threadcount++;try{
socket= newSocket(addr, MultiJabberServer.PORT);
}catch(IOException e) {
}try{
in= new BufferedReader(newInputStreamReader(
socket.getInputStream()));
out= new PrintWriter(new BufferedWriter(newOutputStreamWriter(
socket.getOutputStream())),true);
start();
}catch(IOException e) {try{
socket.close();
}catch(IOException e2) {
}
}
}public voidrun() {try{for (int i = 0; i < 25; i++) {
out.println("Client " + id + ":" +i);
String str=in.readLine();
System.out.println(str);
}
out.println("END");
}catch(IOException e) {
}finally{try{
socket.close();
}catch(IOException e2) {
threadcount--;
}
}
}
}public classMultiJabberClient {static final int MAX_THREADS = 40;public static void main(String[] args) throwsIOException,
InterruptedException {
InetAddress addr= InetAddress.getByName(null);while (true) {if (JabberClientThread.threadCount()
Thread.currentThread().sleep(100);
}
}
}