// Collection of code snippets by Arne VajhÃ¸j 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import java.io.*;
import java.net.*;

public class ClientText {
    public static void main(String[] args) {
        try {
            // connect til server
            Socket s = new Socket("localhost", 12345);
            PrintWriter pw = new PrintWriter(s.getOutputStream());
            BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
            String line;
            String[] parts;
            // skriv til server
            int a = 12;
            int b = 34;
            pw.println("ADD " + a + " " + b);
            pw.flush();
            // læs fra server og skriv resultat til skærm
            line = br.readLine();
            parts = line.split(" ");
            int c = Integer.parseInt(parts[1]);
            System.out.println(c);
            // skriv til server
            String s1 = "abc";
            pw.println("DUP " + s1);
            pw.flush();
            // læs fra server og skriv resultat til skærm
            line = br.readLine();
            parts = line.split(" ");
            String s2 = parts[1];
            System.out.println(s2);
            // disconnect
            br.close();
            pw.close();
            s.close();
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
