// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package jcademo.client;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.util.UUID;

public class ClientPermTCP {
	public static void main(String[] args) throws IOException {
		// open socket
		Socket s = new Socket("localhost", 10004);
		PrintStream ps = new PrintStream(s.getOutputStream(), true, "UTF-8");
		BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream(), "UTF-8"));
		for(int i = 0; i < 3; i++) {
			// send lines with id and numbers to add
			ps.println(UUID.randomUUID());
			ps.println("123 456");
			ps.flush();
			// read and output id and response lines
			String id = br.readLine();
			System.out.println(id);
			String line = br.readLine();
			System.out.println(line);
		}
		// close
		br.close();
		ps.close();
		s.close();
	}
}
