package fr.upem.net.tcp;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ClientLongSum {

	private static ArrayList<Long> randomLongList(int size){
		Random rng= new Random();
		ArrayList<Long> list= new ArrayList<>(size);
		for(int i=0;i<size;i++){
			list.add(rng.nextLong());
		}
		return list;
	}

	private static boolean checkSum(List<Long> list, long response) {
		long sum = 0;
		for(long l : list)
			sum += l;
		return sum==response;
	}

	private static long requestSumForList(SocketChannel sc, List<Long> list) throws IOException {
	  // TODO
	  return 0L;
	}

	public static void main(String[] args) throws IOException {
		InetSocketAddress server = new InetSocketAddress(args[0],Integer.valueOf(args[1]));
		try (SocketChannel sc = SocketChannel.open(server)) {
			for(int i=0; i<5; i++) {
				ArrayList<Long> list = randomLongList(50);
				long l = requestSumForList(sc, list);
				if (!checkSum(list, l)) {
					System.err.println("Oups! Something wrong happens!");
				}
			}
			System.err.println("Everything seems ok");
		}
	}
}