import java.net.*; import java.io.*; public class srv { static String port = "5194"; public static void main(String[] argv) { if (argv.length == 0) srv(port); else srv(argv[0]); } public static void srv(String port) { // tcp/ip version try { ServerSocket server = new ServerSocket(Integer.parseInt(port)); while (true) { Socket sock = server.accept(); System.err.println("srv " + sock); echo(sock); sock.close(); } } catch (IOException e) { e.printStackTrace(); } } static void echo(Socket sock) throws IOException { DataInputStream in = new DataInputStream(sock.getInputStream()); DataOutputStream out = new DataOutputStream(sock.getOutputStream()); String s; while ((s = in.readLine()) != null) { out.writeBytes(s); out.writeByte('\n'); out.flush(); if (s.equals("exit")) break; } } }