import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class ChatServer { public static final int PORT = 2001; public static void main(String[] args) { final SimpleLogger logger = new SimpleLogger("ChatServer"); final MainServerThread server = new MainServerThread(); server.start(); try { ServerSocket s; s = new ServerSocket(PORT); logger.log("Server-socketen: " + s); logger.log("Servern lyssnar..."); while(true) { logger.log("Väntar på uppkoppling från klient..."); // Blocks until a connection occurs: Socket socket = s.accept(); logger.log("Uppkoppling från klient accepterad."); logger.log("Den nya socketen: " + socket); final BufferedReader from_client = new BufferedReader(new InputStreamReader(socket.getInputStream())); final PrintWriter to_client = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true); // true: PrintWriter is line buffered server.new_client(from_client, to_client); } } catch (IOException e) { logger.log("IOException: " + e); e.printStackTrace(); } } // main } // class ChatServer