import java.net.*; import java.io.*; import java.util.*; public class chatserver implements Runnable { public static final int PORT = 8765; protected ServerSocket listen; protected Vector connections; Thread connect; public chatserver() { try { listen = new ServerSocket(PORT); } catch (IOException e) { System.err.println("Fehler beim Erzeugen der Sockets:"+e); System.exit(1); } connections = new Vector(); connect = new Thread(this); connect.start(); } public void run() { try { while(true) { Socket client=listen.accept(); connection c = new connection(this, client); connections.addElement(c); } } catch (IOException e) { System.err.println("Fehler beim Warten auf Verbindungen:"+e); System.exit(1); } } public static void main(String[] args) { new chatserver(); } public void broadcast(String msg) { int i; connection you; for (i=0; i<connections.size(); i++) { you = (connection) connections.elementAt(i); you.out.println(msg); } } }