package Server; import java.net.*; import java.io.*; import java.util.LinkedList; import java.util.Iterator; public class ChatServer { private ServerSocket service; private LinkedList connections; public static final int portNum = 6667; public static ChatServer server; public void connectionRemove(Connection con) { this.connections.remove(con); } public Iterator getConnectionIterator() { return this.connections.iterator(); } ChatServer() throws IOException { this.service = new ServerSocket(portNum); this.connections = new LinkedList(); } /** Listening to port and opening a socket */ public static void main(String[] args) throws IOException { try { server = new ChatServer(); } catch (IOException e) { System.err.println("Failed listening on port " + portNum + " (" + e + ")"); return; } Socket soc = null; try { while (true) { soc = server.service.accept(); Connection con = new Connection(soc); server.connections.add(con); con.start(); } } catch (IOException e) { System.out.println(e); } } } /** Tasks * * * Allow listening on a different port (from command-line?) * * Have a test server running on cohens.org.il * * Send requests to all clients (use list) * - When a client disconnects - remove it from connections list. * - temporary: When we get a PRIVMSG, iterate over connections and write message and every client * - When we get a PRIVMSG, iterate over connections and write the message to each client * * Don't allow two clients with the same nick * * When passing a message (PRIVMSG) - include the sender's nick. * * Keep channels up: PING occasionally * * Graphical interface for server */