import java.net.*;
import java.io.*;
import java.util.Scanner;

public class EchoClient 
{
    private Socket clientSocket;
    private PrintWriter out;
    private BufferedReader in;

    public void startConnection(String ip, int port) throws IOException, UnknownHostException
    {
        clientSocket = new Socket(ip, port);
        out = new PrintWriter(clientSocket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    }

    public String sendMessage(String msg) throws IOException
    {
        out.println(msg);
        String resp = in.readLine();
        return resp;
    }

    public void stopConnection() throws IOException
    {
        in.close();
        out.close();
        clientSocket.close();
    }

    public static void main(String args[]) throws IOException
    {
        Scanner kb = new Scanner(System.in);
        GreetClient client = new GreetClient();
        client.startConnection("127.0.0.1", 4444);
        String inline;
        inline = kb.nextLine();
        while(inline.length() != 0)
        {
          String response = client.sendMessage(inline);
          System.out.println(response);
          inline = kb.nextLine();
        }
       client.stopConnection();
     }
}
