import java.net.*;
import java.io.*;

class EchoServer {

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(7);
        } catch (IOException ioe) {
            System.err.println("Couldn't listen on port 7");
            System.exit(1);
        }

        Socket clientSocket = null;
        try {
            clientSocket = serverSocket.accept();
        } catch (IOException ioe) {
            System.out.println("Accept failed: 7");
            System.exit(-1);
        }

        try {
            PrintWriter out =
                    new PrintWriter(clientSocket.getOutputStream(), true);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(clientSocket.getInputStream()));

            String input = in.readLine();
            out.println(input);

            out.close();
            in.close();
            clientSocket.close();
            serverSocket.close();
        } catch (IOException ioe) {
            System.err.println("Couldn’t communicate with client");
        }
    }
}

