import java.io.*;
import java.net.*;

public class EchoServer {
  
  public static void main(String[] args) throws IOException {
    Socket echoSocket = null;        
    PrintStream out = null;
    DataInputStream in = null;        
    
    ServerSocket server=null;
    
    try {
      server = new ServerSocket(2007);
      echoSocket = server.accept();
    } catch (IOException e) {
      System.err.println(e);
      System.exit(1);
    }
    
    try {
      out = new PrintStream(echoSocket.getOutputStream());
      in = new DataInputStream(echoSocket.getInputStream());
    } catch (IOException e) {
      System.err.println(e);
      System.exit(1);        
    }
    
    String userInput;  
    while ((userInput = in.readLine()) != null) {
      out.println(userInput);      
      System.out.println("echo: " + userInput);  
    }
    out.close();  
    in.close();
    echoSocket.close();
    server.close();
  }
}

