import java.net.*;
import java.io.*;
import javax.swing.plaf.SliderUI;
public class Client{
public static void main(String[] args){
try{
ServerSocket listen = new ServerSocket(10002);
Socket sock = new Socket("127.0.0.1", 10001);
BufferedReader keybord = new BufferedReader(new InputStreamReader(System.in));
OutputStream out = sock.getOutputStream();
InputStream in = sock.getInputStream();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = null;
while(true){
System.out.print("C> ");
line = keybord.readLine();
if(line.equals("exit")){
System.out.println("Good Bye!!");
break;
}
else if(line.equals("list")){
pw.println(line);
pw.flush();
Socket client = listen.accept();
InputStream lin = client.getInputStream();
BufferedReader lbr = new BufferedReader(new InputStreamReader(lin));
line = lbr.readLine();
System.out.println(line);
lbr.close();
}
else if(line.equals("get")){
pw.println(line);
pw.flush();
Socket client = listen.accept();
InputStream lin = client.getInputStream();
BufferedReader lbr = new BufferedReader(new InputStreamReader(lin));
line = lbr.readLine();
System.out.println(line);
lbr.close();
}
else if(line.equals("put")){
pw.println(line);
pw.flush();
Socket client = listen.accept();
InputStream lin = client.getInputStream();
BufferedReader lbr = new BufferedReader(new InputStreamReader(lin));
line = lbr.readLine();
System.out.println(line);
lbr.close();
}
else{
pw.println(line);
pw.flush();
Socket client = listen.accept();
InputStream lin = client.getInputStream();
BufferedReader lbr = new BufferedReader(new InputStreamReader(lin));
line = lbr.readLine();
System.out.println(line);
lbr.close();
}
}
pw.close();
br.close();
sock.close();
}catch(Exception e){
System.out.println("C> " + e);
}
}
}