/** * DumpServer.java * * Quelle: Java Buch (Schader) * * Version $Id$ */ import java.io.*; import java.net.*; class DumpServer { static PrintWriter out = new PrintWriter(System.out, true); static void antwort(BufferedReader sockin) throws IOException { String str; try { while ((str = sockin.readLine()) != null) out.println(str); } catch (IOException ign) { } } DumpServer(int port) { try { final int MAX_VERB = 100; ServerSocket server = new ServerSocket(port); out.println("[Server wartet auf Port " + port + "]"); for (int i = 0; i < MAX_VERB; i++) { Socket sock = server.accept(); out.println("[Verbindung zu " + sock.getInetAddress() + ":" + sock.getPort() + "]"); BufferedReader sockin = new BufferedReader(new InputStreamReader(sock.getInputStream())); antwort(sockin); out.println("[Verbindung getrennt]"); } server.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } public static void main(String[] args) { if (args.length == 1) new DumpServer(Integer.parseInt(args[0])); else out.println("Starten mittels java DumpServer "); } }