Archivo: /home/misan/workplace/IMServer/IMServer.
java Página 1 de 1
import [Link].*;
import [Link].*;
import [Link].*;
class IMServer extends Thread {
Scanner in;
PrintWriter out;
static ArrayList<PrintWriter> pool = new ArrayList<PrintWriter>();
public IMServer(Socket s) throws IOException {
in = new Scanner([Link]());
out = new PrintWriter([Link](),true);
[Link](out);
start();
}
public static void main(String args[]) throws IOException {
ServerSocket ss = new ServerSocket(7777);
while(true) new IMServer([Link]());
}
public void broadcast(String l ) {
synchronized (pool) { for(PrintWriter output : pool) // NEW HERE
if (  ) [Link](l); }
}
public void run() {
broadcast("NEW CLIENT");
try {
while(true) {
String line = [Link]();
if ([Link]("quit")) break; else broadcast(line);
}
} catch (Exception e) {[Link]("Exception "+e);}
synchronized (pool) {[Link](out);} // NEW HERE
[Link]();
broadcast("CLIENT GONE");
}
}